我正在使用Entity框架并且数据库AddedDate中有1个字段是DateTime而不是null,所以我需要传递DateTime值。
但问题是我必须通过DB Server datetime 。 如何管理此场景或如何让DB Server数据时间通过此功能。
我需要一些独特的解决方案,因为我是多种形式的。
编辑:我在应用程序中插入/更新时需要DB服务器日期时间,以便我可以传递给实体框架对象。
谢谢
I am using Entity framework and have 1 field in database AddedDate that is DateTime and not null, so I need to pass DateTime value.
But the problem is I have to pass DB Server datetime. How can I manage in this sceario or how can I get DB Server datatime to pass this.
I need to some unique solution, because I am this on many forms.
Edit: I need DB server Datetime upon insertion/updation in my application so that I can pass to entity framework object.
Thanks
最满意答案
由于您使用的是实体框架,因此可以执行以下操作:
var dateQuery = yourDbContext.CreateQuery<DateTime>("CurrentDateTime() "); DateTime dateFromSql = dateQuery .AsEnumerable().First();Since you are using entity framework, you can do something like this:
var dateQuery = yourDbContext.CreateQuery<DateTime>("CurrentDateTime() "); DateTime dateFromSql = dateQuery .AsEnumerable().First();更多推荐
发布评论