How to turn off NHibernate's automatic (dirty checking) update behaviour?

前端 未结 4 722
臣服心动
臣服心动 2020-12-15 03:40

I\'ve just discovered that if I get an object from an NHibernate session and change a property on object, NHibernate will automatically update the object on commit without m

4条回答
  •  渐次进展
    2020-12-15 04:47

    You can set Session.FlushMode to FlushMode.Never. This will make your operations explicit

    ie: on tx.Commit() or session.Flush(). Of course this will still update the database upon commit/flush. If you do not want this behavior, then call session.Evict(yourObj) and it will then become transient and NHibernate will not issue any db commands for it.

    Response to your edit: Yes, that guy gives you more options on how to control it.

提交回复
热议问题