Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 日期时间值如何舍入EF_Entity Framework_Sql Server 2005 - Fatal编程技术网

Entity framework 日期时间值如何舍入EF

Entity framework 日期时间值如何舍入EF,entity-framework,sql-server-2005,Entity Framework,Sql Server 2005,当我在EF中使用DateTime属性时,它会映射到一个sqlDateTime字段。提供的精度对我来说已经足够了,但是因为它是键的一部分,所以我需要一种方法来检查数据库中是否已经存在值。EF如何将DateTime.NET数据类型四舍五入为DateTimeSQL数据类型?实体框架将数据作为 thedatetime.ToString("yyyy-MM-dd HH:mm:ss.fff",CultureInfo.InvariantCulture) Sql server对此进行了如下处理: 0.899 &

当我在EF中使用
DateTime
属性时,它会映射到一个sql
DateTime
字段。提供的精度对我来说已经足够了,但是因为它是键的一部分,所以我需要一种方法来检查数据库中是否已经存在值。EF如何将
DateTime
.NET数据类型四舍五入为
DateTime
SQL数据类型?

实体框架将数据作为

thedatetime.ToString("yyyy-MM-dd HH:mm:ss.fff",CultureInfo.InvariantCulture)
Sql server对此进行了如下处理:

0.899 <= x < 0.992 -> 0.900
0.992 <= x < 0.995 -> 0.903
0.995 <= x < 0.999 -> 0.907
0.899 0.900
0.992  0.903
0.995  0.907

要检查密钥,您不需要知道“舍入”。如果您使用
context.DbSet().Any(x=>x.DateField==SomeDateValue)
如果密钥存在或不存在,您现在将看到。不幸的是,没有。我在下面回答我自己的问题。