Joseph Daigle
Joseph Daigle

Reputation: 48448

Using NHibernate to insert/update using a SQL server-side DEFAULT value

Several of our database tables contain LastModifiedDate columns. We would like these to stay synchronized based on a single time-source. Our best time-source, in this case, is the SQL Server itself since there is only one database server but multiple application servers which could potentially be off sync.

I would like to be able to use NHibernate, but have it use either GETUTCDATE() or DEFAULT for the column value when updating or inserting rows on these tables.

Thoughts?

Edit: Based on the lack of responses, I simply have to believe that this is something that NHibernate is just not capable of doing. This makes me sad.

Upvotes: 1

Views: 1447

Answers (2)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

Since you want to use a server function for BOTH insert and update, and you probably want to keep that consistent in memory, I suggest that you use a trigger and then set:

insert="false" update="false" generated="always".

That way, NHibernate will retrieve the inserted/updated value from the DB whenever you save.

Upvotes: 1

Nuno G
Nuno G

Reputation: 2105

When mapping the class property to the table column, set insert="false" update="false".

Upvotes: 2

Related Questions