views:

19

answers:

1

Is it possible to configure Linq to SQL to update a column as getutcdate() (ie. obtain the date from the db server, rather than the web server), or is a trigger my only option?

I have tried setting the Time Stamp property on the model, but that did not help.

Any thoughts?

+1  A: 

I think you need to use a trigger to update the time. The way I handle it is to mark the property in the LINQ designer as readonly and server generated. I set up a trigger on update to modify the column on every update. For created dates, I do the same readonly/server generated and use getdate() as the column default. Setting the column to server generated is important as you don't want it to send data back for that column which may be incorrect -- either NULL, the old date, or DateTime.Minumum, depending on the type and the initial setting.

Another alternative would be to handle it in code and update the column using PropertyChanged event handlers for each column on the class. I think it's easier to go the trigger route. Note that this will use the web server time, not the DB time -- but they should be in sync anyway (they have to be if you're using secure connections). You could conceivably do a select to get the DB server time, but then you'd always be off by the round-trip time. As I said, I think the trigger is easier.

tvanfosson
I had a feeling a trigger was needed. I ended up using an `INSTEAD OF` trigger to reduce the hits on the transaction log, and I removed the property from the model entirely (it's not required by the application).
Richard Szalay