views:

176

answers:

0

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?