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

前端 未结 4 718
臣服心动
臣服心动 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:46

    My solution:

    1. In your initial ISession creation, (somewhere inside your injection framework registrations) set DefaultReadOnly to true.
    2. In your IRepository implementation which wraps around NHibernate and manages the ISession and such, in the Insert, Update, InsertUpdate and Delete (or similar) methods which call ISession.Save, Update, SaveUpdate, etc., call SetReadOnly for the entity and flag set to false.

提交回复
热议问题