Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyObj {
- public string Id { get; set; }
- [Increment]
- public int OtherProp { get; set; }
- }
- public class OtherPropIncrementListener : IDocumentStoreListener {
- HiLoKeyGenerator _generator;
- IDocumentStore _store;
- public BlavenIdStoreListener(IDocumentStore store) {
- this._store = store;
- _generator = new HiLoKeyGenerator(store.DatabaseCommands, "MyObjs", 1);
- }
- public void AfterStore(string key, object entityInstance, RavenJObject metadata) { }
- public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original) {
- var myObj = entityInstance as MyObj;
- if(myObj != null && myObj.OtherProp == 0) {
- string documentKey = _generator.GenerateDocumentKey(_store.Conventions, entityInstance);
- myObj.OtherProp = int.Parse(documentKey.Substring(documentKey.IndexOf("/") + 1));
- return true;
- }
- return false;
- }
- }
- documentStore.RegisterListener(new BlavenIdStoreListener(documentStore));
Add Comment
Please, Sign In to add comment