Skip to content

Instantly share code, notes, and snippets.

@jesuslpm
Created October 9, 2012 15:23
Show Gist options
  • Save jesuslpm/3859492 to your computer and use it in GitHub Desktop.
Save jesuslpm/3859492 to your computer and use it in GitHub Desktop.
session.Store(entity, etag) ignores the etag if the entity is the session
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Document;
using Raven.Client.Embedded;
using Raven.Client;
namespace Test
{
public class Foo
{
public string Id { get; set; }
public string Name { get; set; }
}
class Program
{
static IDocumentSession currentSession;
static void Main(string[] args)
{
using (DocumentStore store = new EmbeddableDocumentStore { RunInMemory = true })
{
store.Initialize();
using (var session = store.OpenSession())
{
session.Advanced.UseOptimisticConcurrency = true;
session.Store(new Foo
{
Id = "Foos/1",
Name = "Foo"
});
session.SaveChanges();
}
using (var session = store.OpenSession())
{
session.Advanced.UseOptimisticConcurrency = true;
currentSession = session;
var foo1 = session.Load<Foo>("Foos/1");
foo1.Name = "Other name";
var etag = Guid.Parse("{00000000-0000-0000-0000-000000000001}");
// If I remove Evict no ConcurrenyException is raised
session.Advanced.Evict(foo1);
session.Store(foo1, etag);
session.SaveChanges();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment