Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I force RavenDB to allow IDocumentSession.Store() to accept an entity with existing id?
    primarykey
    data
    text
    <p>I have an application which I am upgrading from RavenDB 1 to RavenDB 2. The application does not store its domain object in the database directly. Instead, the domain objects are converted into document objects prior to persistance (and vice versa when reading). For example, a domain object:</p> <pre><code>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) { ... } . . . } </code></pre> <p>And the corresponing document object (which is what gets stored in the database):</p> <pre><code>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() { ... } } </code></pre> <p>So, if I want to change a user document stored in the database, I would typically load it, convert it into its corresponing domain object, make the changed (e.g call ChangePassword()), convert the domain object back into a document object and finally call IDocumentSession.Store() and SaveChanges(). This worked fine in RavenDB 1.</p> <p>In RavenDB 2, however, it seems I am not allowed to call IDocumentSession.Save() with an entity that has the Id property set to a taken Id. When updating a document, the Id property will, by definition, already be taken.</p> <p>The idea seems to be that in RavenDB 2 I would load an object, change it and then call SaveChanges() and the client would keep track of which objects that have been loaded and automatically send them to the server. Since I will make all changes in a proxy object (the domain object) and don't have the original document object left in memory, that is not possible for me.</p> <p>Is it possible to configure RavenDB to use the behaviour present in RavenDB 1?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload