One option is adding versioning to your entities.

http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-version

You will need to add a version column to your table, as well as a version 
property.  I use a nullable int for this.  If the version property is null, 
NHibernate will treat the object as a new, unsaved object and issue inserts, no 
matter the ID.  If the version property is NOT null, it will know that the 
object already exists and issue an UPDATE statement.

From: [email protected] [mailto:[email protected]] On Behalf Of 
Zsolt Soczo
Sent: Wednesday, September 14, 2011 2:27 PM
To: [email protected]
Subject: [nhusers] Working with assigned ids

Hello,
  we have decided to use client side generated Guids for entity keys. However, 
this cause problems when I want to insert an entity with children entities.
Nhibernate does not know whether the children are persistent in the database, 
so it must query them first and decide about the insert or update. This is very 
logical, but how can I help it to know which child object is new and which is 
already persisted?
I can't use a zero guid to flag the entity as transient because of the very 
reason the id is generated on the client side. So, who can I give nhibernate 
the necessarily info to decide about the persistence state of the objects?

Thanks,
Zsolt
--
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to