Creation and change stamping of entities
Although it does not track the full history of an entity, another option for auditing is to record information about the entity's creation and the most recent change directly in the entity. In this recipe, we will show you how to use NHibernate's events to record creation and change data on your entities.
How to do it…
- Create a new class library project named
Changestamp
. - Install the
NHibernate
package using the NuGet Package Manager Console by executing the following command:Install-Package NHibernate
- Create an interface named
IStampedEntity
with the following code:public interface IStampedEntity { string CreatedBy { get; set; } DateTime CreatedTS { get; set; } string ChangedBy { get; set; } DateTime ChangedTS { get; set; } }
- Create an interface named
IStamper
with the following code:public interface IStamper { void Insert(IStampedEntity entity, object[] state, IEntityPersister persister); void Update(IStampedEntity...