LINQ到实体SqlFunctions.DateDiff不支持 [英] Linq to Entities SqlFunctions.DateDiff not supported

查看:1002
本文介绍了LINQ到实体SqlFunctions.DateDiff不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆