We use it to do some time version control and need this behavior.
Warning hackers ahead
I haven’t tried this, so this is just thinking aloud about how nhibernate tracks objects.
p>
According to the object graph, you can reset the version (if any) and reset the id to the default value specified in the mapping, and a clone should be created because it effectively resets how nhibernate tracks the object, And it will be given a new Id when saving. Please also note that any additional mapping objects also need to complete the same operation to get a deep clone.
If it was me, I might be on the object Put a clone method that returns a new object with a copy of the properties, and so on.
Some other answers on SO suggest using Automapper How to clone objects in NHibernate?
Is there a way for NHibernate to clone an existing object (retrieved by nhibernate) and perform an insert on it to create a new record instead of updating the current object.
We use It does some kind of time version control and requires this behavior.
I don’t know anything built into nhibernate can accomplish the goal you are pursuing. [ If any) and reset the id to the default value specified in the mapping, and a clone should be created, because it effectively resets how nhibernate tracks the object, and it will be given a new Id when saving. Also please Note that any additional mapping objects also need to complete the same operation to obtain a deep clone.
If it were me, I might put a clone method on the object, which returns a new copy with a copy of the property Objects, etc.
Some other answers on SO suggest using Automapper How to cl one objects in NHibernate?