Entity Framework losing Sql DateTime precision

Deadly 提交于 2019-12-06 19:56:32

问题


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.


回答1:


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 ).



来源:https://stackoverflow.com/questions/6784110/entity-framework-losing-sql-datetime-precision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!