In NHIbernate, why does SaveOrUpdate() update the Version, but SaveOrUpdateCopy() doesn't?
Posted
by Daniel T.
on Stack Overflow
See other posts from Stack Overflow
or by Daniel T.
Published on 2010-04-24T08:14:29Z
Indexed on
2010/04/24
8:23 UTC
Read the original article
Hit count: 512
I have a versioned entity, and this is what happens when I use SaveOrUpdate()
vs. SaveOrUpdateCopy()
:
// create new entity
var entity = new Entity{ Id = Guid.Empty });
Console.WriteLine(entity.Version); // prints out 0
// save the new entity
GetNewSession();
entity.SaveOrUpdate();
Console.WriteLine(entity.Version); // prints out 1
GetNewSession();
// loads the persistent entity into the session, so we have to use
// SaveOrUpdateCopy() to merge the following transient entity
var dbEntity = Database.GetAll<Entity>();
// new, transient entity used to update the persistent entity in the session
var newEntity = new Entity{ Id = Guid.Empty });
newEntity.SaveOrUpdateCopy();
Console.WriteLine(entity.Version); // prints out 1, but should be 2
Why is the version number is not updated for SaveOrUpdateCopy()
? As I understand it, the transient entity is merged with the persistent entity. The SQL calls confirm that the data is updated. At this point, shouldn't newEntity
become persistent, and the version number incremented?
© Stack Overflow or respective owner