NHIBERNATE: Insert and Update Date

What is the best way to handle InsertDate (a.k.a CreateDate) and UpdateDate columns using NHibernate?

For example:

public class Customer 
{
public virtual string Name {get; set; }
public virtual DateTime InsertDate {get; set; }
public virtual DateTime UpdateDate {get; set; }
}

There may be multiple ways to solve this problem, but before People who have done this may give me some suggestions.

If it is not obvious, I would like to set InsertDate to the date when the record was inserted, and then set it to immutable. It is required every time the record is updated Change UpdateDate.

If you use Fluent Nhibernate to answer, you can get rewards.

Use audit interceptors for this. A good example can be found here.

Using NHibernate, what is the best way to handle InsertDate (aka CreateDate) and UpdateDate columns?

For example:

public class Customer 
{
public virtual string Name {get; set; }
public virtual DateTime InsertDate {get; set; }
public virtual DateTime UpdateDate {get; set; }
}

There may be multiple ways to solve this problem, but before People who have done this may give me some suggestions.

If it is not obvious, I would like to set InsertDate to the date when the record was inserted, and then set it to immutable. It is required every time the record is updated Change UpdateDate.

If you use Fluent Nhibernate to answer, you can get rewards.

Use an audit interceptor for this. A good one Examples can be found here.

Leave a Comment

Your email address will not be published.