NHibernate: insert and update dates

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

For instance:

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

There are probably several ways this can be handled, but maybe someone who has done this before giving me some advice.

If this is not obvious, I want InsertDate to be set to the date the record was inserted, and after that to be unchanged. UpdateDate needs to be changed every time a record is updated.

Bonus points if you respond using Fluent Nhibernate.

+4
source share
2 answers

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

+2
source

I used something similar to Ayende Rahien .

Not so important - just to be complete - my version used interceptors, not listeners. For more information for interceptors and listeners, read this thread_stack question .

+2
source

All Articles