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…

  1. Create a new class library project named Changestamp.
  2. Install the NHibernate package using the NuGet Package Manager Console by executing the following command:
    Install-Package NHibernate
    
  3. 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 NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.