views:

223

answers:

2

I want to track changes in my domain model. I know that NHibernate ISession is an inmplementation of UnitOfWork pattern, so it tracks this changes. Is there any way to pull out them, for example, before Commit() or Flush()?

+1  A: 

Take a look at NHibernate's IInterceptor.

OnFlushDirty - will show you persisted properties on an updated object.

OnSave - will shows you persisted properties on a saved object.

You just need to create an interceptor class that implements this interface, and when you configure your NHibernate session, tell it to use that class.

Here is a fairly good article to help you get started

jasonlaflair
+1  A: 

I think than Interceptors are a little bit obsolete. Еrying to use NHibernate Events. I've subscribed on OnPreUpdate event. It's parameter has State and OldState properties, but OldState is allways null. Does anyone know this OldState works at all?

Alkersan