c# - Can I force RavenDB to allow IDocumentSession.Store() to accept an entity with existing id? -


i have application upgrading ravendb 1 ravendb 2. application not store domain object in database directly. instead, domain objects converted document objects prior persistance (and vice versa when reading). example, domain object:

public class user {     public string id { get; private set; }     public string email { get; set; }     public string passwordsalt { get; private set; }     public string passwordhash { get; private set; }      public void changepassword(string oldpassword, string newpassword) {         ...     }     .     .     . } 

and corresponing document object (which gets stored in database):

class userdocument {     public static userdocument fromentity(user user) {         ...     }      public string id { get; set; }     public string email { get; set; }     public string passwordsalt { get; set; }     public string passwordhash { get; set; }      public user toentity() {         ...     } } 

so, if want change user document stored in database, typically load it, convert corresponing domain object, make changed (e.g call changepassword()), convert domain object document object , call idocumentsession.store() , savechanges(). worked fine in ravendb 1.

in ravendb 2, however, seems not allowed call idocumentsession.save() entity has id property set taken id. when updating document, id property will, definition, taken.

the idea seems in ravendb 2 load object, change , call savechanges() , client keep track of objects have been loaded , automatically send them server. since make changes in proxy object (the domain object) , don't have original document object left in memory, not possible me.

is possible configure ravendb use behaviour present in ravendb 1?

the idea not have such separation between user , userdocument. want storing user objects ravendb using idocumentsession - fact being stored documents implementation details far should concerned.

there isn't real difference between ravendb 1 , 2 in regard.

you should able 1 of two:

  1. load object using idocumentsession.load (or query), change unit-of-work directly , call savechanges when done

  2. load object, change obeject (using copy constructor or like) , store new object under same id. can calling session.store(obj, null, id).


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -