Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - auto generate timestamp on create and update?

I am trying to map an entity in NHibernate, that should have an Updated column. This should be the DateTime when the entity was last written to the database (either created or updated). I'd like NHibernate to control the update of the column, so I don't need to remember to set a property to the current time before updating.

Is there a built-in feature in NHibernate, that can handle this for me ?

like image 660
driis Avatar asked Apr 21 '10 08:04

driis


1 Answers

Use a Listener that implements IPreUpdateEventListener and IPreInsertEventListener. This article explains how. Note that this uses the user's time and that may not be appropriate for your application.

like image 90
Jamie Ide Avatar answered Oct 26 '22 17:10

Jamie Ide