在应用程序中获取DB Server DateTime(Getting DB Server DateTime in application)

编程入门 行业动态 更新时间:2024-10-28 00:16:45
应用程序中获取DB Server DateTime(Getting DB Server DateTime in application)

我正在使用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();

更多推荐

本文发布于:2023-07-16 04:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1123456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   DB   Server   DateTime   application

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!