O'Reilly logo

NHibernate 4.x Cookbook - Second Edition by Jason Dentler, Alexander Zaytsev, Gunnar Liljas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required