SHARE
TWEET

Untitled

a guest Jan 18th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyObj {
  2.     public string Id { get; set; }
  3.     [Increment]
  4.     public int OtherProp { get; set; }
  5. }
  6.    
  7. public class OtherPropIncrementListener : IDocumentStoreListener {
  8.     HiLoKeyGenerator _generator;
  9.     IDocumentStore _store;
  10.     public BlavenIdStoreListener(IDocumentStore store) {
  11.         this._store = store;
  12.         _generator = new HiLoKeyGenerator(store.DatabaseCommands, "MyObjs", 1);
  13.     }
  14.  
  15.     public void AfterStore(string key, object entityInstance, RavenJObject metadata) { }
  16.  
  17.     public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original) {
  18.         var myObj = entityInstance as MyObj;
  19.         if(myObj != null && myObj.OtherProp == 0) {
  20.             string documentKey = _generator.GenerateDocumentKey(_store.Conventions, entityInstance);
  21.             myObj.OtherProp = int.Parse(documentKey.Substring(documentKey.IndexOf("/") + 1));
  22.             return true;
  23.         }
  24.         return false;
  25.     }
  26. }
  27.    
  28. documentStore.RegisterListener(new BlavenIdStoreListener(documentStore));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top