我将列ModificationDate作为TimeStamp存储在数据库中。 我正在使用Oracle 12c数据库。
当我想将这个日期与其他日期进行比较时,它似乎在比较期间失去了精确度,或者发生了其他事情......
数据库中的日期值是' 15/12/07 15:37:26,562000000'。而我正在使用此查询:
DateTime date = new DateTime(2015, 12, 07, 15, 37, 26, 562);
var p1 = from p in entities.People
where p.ModificationDate > date
select p;
Console.WriteLine(p1.Count()); //Prints: 1
//Where condition: "Extent1"."MODIFICATIONDATE" > :p__linq__0
var p2 = from p in entities.People
where p.ModificationDate > new DateTime(2015, 12, 07, 15, 37, 26, 562)
select p;
Console.WriteLine(p2.Count()); //Prints: 0
//Where condition: "Extent1"."MODIFICATIONDATE" > TO_TIMESTAMP('2015-12-07 15:37:26.562', 'YYYY-MM-DD HH24:MI:SS.FF')
为什么当我将日期时间变为变量时,我得到的结果不正确? 是否有可能使其与datetime变量一起正常工作?
编辑: 经过几次尝试,我找到了更简单的例子:
DateTime date = new DateTime(2015, 12, 07, 15, 37, 26, 562);
var p3 = from p in entities.PEOPLE
where date == new DateTime(2015, 12, 07, 15, 37, 26, 562)
select p;
Console.WriteLine(p3.Count()); //Prints: 0
//Where condition: (TO_TIMESTAMP('2015-12-07 15:37:26.562', 'YYYY-MM-DD HH24:MI:SS.FF') = :p__linq__0) AND (:p__linq__0 IS NOT NULL)
看起来DateTime变量的精度与时间戳不同。是否有可能告诉linq查询将DateTime变量视为TIMESTAMP?