我有两个表(TABLE1、TABLE2 - 我知道是唯一的),它们分别具有一对多关系,并且两个表的 ID 列之间都有外键。
Using linq2sql我正在尝试选择所有TABLE1条目使得它们对应的TABLE2value 在我传递的列表中至少包含 1 项。
这是我使用的一些示例代码LINQPad(很棒的程序)来测试它,但是出现错误NotSupportedException:查询运算符“Any”使用的重载不受支持。
long[] items = { 3, 5, 8 };
var predicate = PredicateBuilder.False<TABLE2>();
foreach (long i in items)
{
long t = i;
predicate = predicate.Or(att => att.ID == t);
}
//TABLE2.Where(predicate).Dump(); //works like a charm
IQueryable query =
from t1 in TABLE1
where t1.TABLE2.AsQueryable().Any(predicate) //problem with this line
select a;
query.Dump();
UPDATE
在 LinqPad 中使用 LinqKit 时,添加对 LinqKit.dll 的引用,取消选中 Include PredicateBuilder,然后在“Additional Namespace Imports”选项卡下添加 LinqKit。
解决方法是
- 调用 AsExpandable()
TABLE1
object
- 对表达式调用 Compile()
变量,当在 EntitySet 上使用时。
所以你的最终查询是
IQueryable query =
from t1 in TABLE1.AsExpandable()
where t1.TABLE2.Any(predicate.Compile()) //the problem should disappear
select a;
更多信息here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)