实体框架丢失Sql DateTime精度 [英] Entity Framework losing Sql DateTime precision

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

问题描述

我正在使用Entity SQL查询我的EDM,并在我的DateTime值上损失了毫秒的精度。例如2011/7/20 12:55:15.333 PM更改为2011/7/20 12:55:15.000 PM。



我已经确认在SQL中精确记录毫秒。



我可以在.edmx XML文件中应用Precision属性,但我不知道需要什么样的值,

 < Property Name =Timestamp
Type =DateTime
Nullable =false
精度=??? />

有谁知道如何使用这个精度属性?



谢谢。

解决方案

这取决于SQL Server版本...参见 http://seesharper.wordpress.com/2008/07/08/sql- server-datetime-vs-net-datetime-battle-of-accuracy /



如果是SQL Server 2008,将数据库中的数据类型更改为datetime2,然后从DB更新模型。



否则,您可以将精度设置为3(小数部分为3位数,请参阅 http://msdn.microsoft.com/en-us/library/cc716737.aspx )。


I am querying my EDM using Entity SQL and am losing millsecond precision on my DateTime values. For example 2011/7/20 12:55:15.333 PM gets changed to 2011/7/20 12:55:15.000 PM.

I have confirmed that in SQL the milliseconds are recorded precisely.

There is a Precision attribute I can apply in the .edmx XML file, but I do not know what sort of values it takes,

      <Property Name="Timestamp"
                Type="DateTime"
                Nullable="false"
                Precision="???" />

Does anyone know how to use this precision attribute ?

Thanks.

解决方案

It depends on the SQL Server version... see http://seesharper.wordpress.com/2008/07/08/sql-server-datetime-vs-net-datetime-battle-of-accuracy/

If it is SQL Server 2008 change the datatype in the DB to datetime2 and then update the model from the DB.

Otherwise you could set Precision to 3 (3 digits for the fractional part, see http://msdn.microsoft.com/en-us/library/cc716737.aspx ).

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

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