实体框架 - 更新域值与当前数据库服务器时间 [英] Entity Framework - update field value to current DB server time

查看:107
本文介绍了实体框架 - 更新域值与当前数据库服务器时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拉回来从数据库中一个实体对象,我需要更新的日期到数据库服务器的日期/时间 - 通常,你可以通过使用SQL GETDATE()设置它做到这一点功能。

我怎样才能在以下情况下做到这一点:

  VAR的客户= context.client.Where(C => c.clientID == 1).FirstOrDefault();//值必须)服务器的当前日期的值,即,GETDATE(...不是DateTime.Now
client.someDate =&所述; someValue中取代;
context.SaveChanges();


解决方案

尝试插入到位样品在第四行的以下内容:

  VAR dateQuery = context.CreateQuery<&日期时间GT(CurrentDateTime());
client.SomeDate = dateQuery.AsEnumerable()(第)。

I've pulling back an entity object from a database and I need to update the date to the DB server's date/time - usually you could accomplish this by setting it with the SQL getDate() function.

How can I accomplish this in the following scenario:

var client = context.client.Where(c=>c.clientID == 1).FirstOrDefault();

// the value needs to be the value of the server's current date, i.e, getDate()... not DateTime.Now
client.someDate = <somevalue>;
context.SaveChanges();

解决方案

Try inserting the following in place of the fourth line in your sample:

var dateQuery = context.CreateQuery<DateTime>("CurrentDateTime() ");
client.SomeDate = dateQuery.AsEnumerable().First();

这篇关于实体框架 - 更新域值与当前数据库服务器时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆