实体框架的Sql失去精度的DateTime [英] Entity Framework losing Sql DateTime precision
问题描述
我查询使用实体SQL我的EDM和我在我的DateTime值失去millsecond精度。例如2011年7月20日12:55:15.333 PM被改为2011年7月20日12:55:15.000 PM
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.
我已经证实,在SQL毫秒精确记录。
I have confirmed that in SQL the milliseconds are recorded precisely.
有一个精密的属性我可以的.edmx XML文件中的适用,但是我不知道什么样的需要值,
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 ?
感谢。
推荐答案
这取决于SQL Server版本......看的http://seesharper.wordpress.com/2008/07/08/sql-server-datetime-vs -net-日期时间,战斗的精度/
It depends on the SQL Server version... see http://seesharper.wordpress.com/2008/07/08/sql-server-datetime-vs-net-datetime-battle-of-accuracy/
如果是SQL Server 2008中的变化在DB的数据类型为DATETIME2,然后更新从模型数据库。
If it is SQL Server 2008 change the datatype in the DB to datetime2 and then update the model from the DB.
否则,你可以设置精密3(3个数字的小数部分,看到的 http://msdn.microsoft.com/en-us/library/cc716737.aspx )。
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屋!