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

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

If I use session-per-transaction and call:

session.SaveOrUpdate(entity) corrected:
session.SaveOrUpdateCopy

4条回答
  •  时光说笑
    2021-01-14 09:21

    I'm not sure I understand your question. The actual saving to the database occurs when the session is flushed (e.g. by committing the transaction). Calling SaveOrUpdate() doesn't itself save the entity, it just informs the session that the entity is due to be saved when the session is flushed.

    Assuming that the ID of the entity maps to an identity field in the database and that your mapping tells NHibernate that identity is set by the database, then the ID set by the database will be set as the entity's ID when it is saved.

提交回复
热议问题