LINQ到实体SqlFunctions.DateDiff不支持 [英] Linq to Entities SqlFunctions.DateDiff not supported
问题描述
我有以下代码
DateTime now = DateTime.UtcNow;
var allItemsOver64 = _inventoryContext.Items.Where(i =>
(SqlFunctions.DateDiff("dd", i.PrimaryInsured.DoB, now) / 365.0) >= 65);
IQueryable<Item> items65To69 = allItemsOver64.Where(i =>
(SqlFunctions.DateDiff("dd", i.PrimaryInsured.DoB, now) / 365.0) >= 65 &&
(SqlFunctions.DateDiff("dd", i.PrimaryInsured.DoB, now) / 365.0) <= 69);
但是,当我尝试使用这样allItemsOver64 Items65To69.Count()我得到这个错误
But when I try and use allItemsOver64 thus Items65To69.Count() I get this error
表达式
((((转换(则DateDiff(DD,[10007] .PrimaryInsured.DoB,26/04/2012 15 :03:09))/ 365)> = 65)
和
((转换(则DateDiff(DD,[10007] .PrimaryInsured.DoB,26/04/2012 15时03分09秒))/ 365)> = 65))
和
((转换(则DateDiff(DD,[10007] .PrimaryInsured.DoB,26/04/2012 15时03分09秒))/ 365)LT;?= 69))$不支持b $ b
The expression ((((Convert(DateDiff("dd", [10007].PrimaryInsured.DoB, 26/04/2012 15:03:09)) / 365) >= 65) And ((Convert(DateDiff("dd", [10007].PrimaryInsured.DoB, 26/04/2012 15:03:09)) / 365) >= 65)) And ((Convert(DateDiff("dd", [10007].PrimaryInsured.DoB, 26/04/2012 15:03:09)) / 365) <= 69)) is not supported.
我在做什么错
推荐答案
也许你可以尝试使用的 EntityFunctions 的,而不是SqlFunctions。
Maybe you could try using EntityFunctions rather than SqlFunctions.
这篇关于LINQ到实体SqlFunctions.DateDiff不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!