配置DateTime列以从db time更新
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

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?

#0

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.

推荐文章

使用NHibernate插入或保存时为对象代理提供的值

使用NHibernate插入或保存时为对象代理提供的值

推荐文章

Jquery稀有函数

Jquery稀有函数

推荐文章

Castle 2.5.3.NET 4尝试通过UNC读取配置文件失败

Castle 2.5.3.NET 4尝试通过UNC读取配置文件失败

推荐文章

WPF密集型UI处理导致ContextSwitchDeadlock

WPF密集型UI处理导致ContextSwitchDeadlock

推荐文章

如何动态设置网格原始数和网格列数?

如何动态设置网格原始数和网格列数?

推荐文章

JBOSS配置

JBOSS配置

推荐文章

我的Google地图自定义覆盖在Chrome和Firefox中不再是“活动的”,但在IE中运行良好

我的Google地图自定义覆盖在Chrome和Firefox中不再是“活动的”,但在IE中运行良好

推荐文章

延迟的作业无法正常工作

延迟的作业无法正常工作

推荐文章

小部件上的UI更新在几个小时后停止,没有错误或异常

小部件上的UI更新在几个小时后停止,没有错误或异常

推荐文章

如何编辑表单输入初始值的字体颜色?

如何编辑表单输入初始值的字体颜色?

推荐文章

无法从USART-FreeRTOS-AT32UC3A0512接收输入

无法从USART-FreeRTOS-AT32UC3A0512接收输入

推荐文章

如何以编程方式更改工具提示绑定?

如何以编程方式更改工具提示绑定?

推荐文章

Objective-C中UIImage的平均颜色值

Objective-C中UIImage的平均颜色值

推荐文章

计算最佳计时器间隔(计时器设置时间)

计算最佳计时器间隔(计时器设置时间)

推荐文章

在从VS2008 C迁移到VS2010之前需要考虑的事项#

在从VS2008 C迁移到VS2010之前需要考虑的事项#

推荐文章

关于二叉搜索树的两个问题

关于二叉搜索树的两个问题