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

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

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

That prevents it from setting the row on INSERT and UPDATE all together. For inserts the DEFAULT value works. But for an update... I want it to actually send "DEFAULT" or "GETUTCDATE()" as the parameter.

Otherwise I'll need to employ database triggers, and I want to avoid where I can. – Joseph Daigle Apr 7 '10 at 12:57 If you are using MS-SQL server, you don't need a trigger. Modify the database table and in the column attributes, set default="Getutcdate()".

– Nuno G Apr 7 '10 at 13:04 1 But that only works on INSERT statements. SQL won't use the default value for an UPDATE unless you set the value as the keyword DEFAULT into your statement. Nbernate won't set this value.

– Joseph Daigle Apr 7 '10 at 13:27 1 Good point. I am afraid you can only do it using triggers. – Nuno G Apr 7 '10 at 14:04 Avoiding triggers when they are clearly the correct tool for the task is short-sighted.

Triggers are a good thing for certain tasks like this, not a bad thing. – HLGEM Apr 7 '10 at 14:16.

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, Nbernate will retrieve the inserted/updated value from the DB whenever you save.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions