Last active
January 1, 2016 09:18
-
-
Save thoemmi/8123604 to your computer and use it in GitHub Desktop.
[Stackoverflow Question 20764813](http://stackoverflow.com/questions/20764813/ravendb-idocumentstorelistener-beforestore-return-false-entity-still-saved)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Raven.Client.Embedded; | |
using Raven.Client.Listeners; | |
using Raven.Json.Linq; | |
namespace StackOverflow20764813 { | |
internal class Program { | |
private static void Main() { | |
using (var store = new EmbeddableDocumentStore { RunInMemory = true }) { | |
store.RegisterListener(new TestDocumentStoreListener()); | |
store.Initialize(); | |
using (var session = store.OpenSession()) { | |
var person = new Person { Name = "Ayende" }; | |
session.Store(person); | |
session.SaveChanges(); | |
} | |
using (var session = store.OpenSession()) { | |
var person = session.Load<Person>(1); | |
// TestDocumentStoreListener.BeforeStore returns false, so the name should still be "Ayende" | |
Debug.Assert(person.Name == "Ayende"); | |
} | |
} | |
} | |
} | |
internal class Person { | |
public string Id { get; set; } | |
public string Name { get; set; } | |
} | |
internal class TestDocumentStoreListener : IDocumentStoreListener { | |
public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original) { | |
var person = (Person) entityInstance; | |
person.Name = "Oren"; | |
return false; | |
} | |
public void AfterStore(string key, object entityInstance, RavenJObject metadata) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment