NHibernate: How is identity Id updated when saving a transient instance?

后端 未结 4 910
我在风中等你
我在风中等你 2021-01-14 08:32

If I use session-per-transaction and call:

session.SaveOrUpdate(entity) corrected:
session.SaveOrUpdateCopy

4条回答
  •  北海茫月
    2021-01-14 09:15

    I noticed I saved by calling:

    session.SaveOrUpdateCopy(entity); 
    

    ..which does NOT update the Id. But by changing to:

    session.SaveOrUpdate(entity);
    

    ..the Id's of transient entity will be updated.

    I probably misunderstood the documentation (?).. Section 9.4.2 says:

    SaveOrUpdateCopy(Object o)... If the given instance is unsaved or does not exist in the database, NHibernate will save it and return it as a newly persistent instance.

    Is it just me, or does it not sound like a transient object (unsaved), will be "returned as persistent" ? Doesn't that mean with updated Id? Would appreciate a clarification how to interpret this sentence correctly (?)

提交回复
热议问题