开发者

Configuring a DateTime column to update from db time

Is it possible to configure Linq to SQL to update a column as getutcdate() (ie. obtain the dat开发者_运维百科e 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜