实体框架,getutcdate() [英] Entity framework, getutcdate()

查看:149
本文介绍了实体框架,getutcdate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用实体框架中的SQL函数getutcdate()在保存实体对象时在数据库中设置日期字段吗?

Can I use the SQL-function getutcdate() from entity framework to set a date field in the database when saving an entity object?

认为
Freddy

regards Freddy

推荐答案

是的,你可以这样做。 CLR功能 DateTime.UtcNow 映射到规范函数 CurrentUtcDateTime ,它应该将SQL Server转换为 GETUTCDATE()或类似的。

Yes, you can do this. The CLR function DateTime.UtcNow is mapped to the canonical function CurrentUtcDateTime, which should translate, for SQL Server to GETUTCDATE() or similar.

var q = from e in Context.MyEntities
        select new
        {
            Entity = e,
            Time = DateTime.UtcNow
        };

这篇关于实体框架,getutcdate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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