views:

442

answers:

2

As I understand it NHibernate has a build in support for timestamps. However, it appears you can only instruct NHibernate to never update the property or always update it.

In the project I am currently working on there are several tables which have both "created_time" and "updated_time", both are to be generated by the database.

I can't figure out how to instruct NHibernate to use "getdate()" for both properties nut only on insert for "created_time" and on insert and update for "updated_time".

Is this possible?

PS: I am working with a legacy database and I am not allowed to change it, so triggers etc. are not possible solutions.

+1  A: 

You could work around this by creating an Interceptor that sets those values, but offcourse, then those values are not generated by the DBMS offcourse ...

It might be a workaround, as I also don't know how to make sure that the DB populates those values, but I'm also interested in another solution for this issue. :)

Frederik Gheysels
In the end I settled for the interceptor solution, but would be nice if there was a special property for this.
Rune Hammerskov
+1  A: 

Which version of NHibernate are you using?

In 2.0, the "generated" tag on a property has three valid values:

  • never (self-explanatory)
  • insert(will retrieve the generated value only on inserts)
  • always (always retrieves generated value).
joshua.ewer