I have mapped ModifiedDate in my NHibernate configuration for most of my entities. Each entity inherits this:
public interface IAuditable {
string ModifiedBy { get; set; }
DateTime ModifiedDate { get; set; }
}
Each class maps these fields to the database, as we want these values read into each entity. I use fluent configuration and map classes.
I have implemented IPreInsert and IPreUpdate event listeners to update the modified by and modified date. This way the audit values will be updated by the framework. I used the code here: http://ayende.com/blog/3987/nhibernate-ipreupdateeventlistener-ipreinserteventlistener
How do I ensure that no matter what values are in ModifiedBy and ModifedDate they are never considered dirty and don't themselves make the entity dirty? The entity must be dirty only when the other fields have changed.
NHibernate.Event.Default.DefaultMergeEventListenerand handle those dates explicitly. - valverij