NHibernate provides many places to expand. Among them is the IInterceptor session. There is documentation with many details:
http://nhibernate.info/doc/nh/en/index.html#objectstate-interceptors
In this case, we can create our custom one, which will observe our object (for example, Client ) and a property that needs to be updated every time (for example, Code ). Thus, our implementation may look like this:
public class MyInterceptor : EmptyInterceptor { public override int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types) { var result = new List<int>();
NOTE. This is just an example! Apply your own logic to check dirty properties.
And we have to wrap Session as follows:
var interceptor = new MyInterceptor() _configuration.SetInterceptor(interceptor);
And this is it. If the Client is marked as dynamic update, the Code property will always be set as dirty.
<class name="Client" dynamic-update="true" ...
source share