在 Linq to Entities 中匹配 2 个列表

Matching 2 lists in Linq to Entities

我正在编写一个表达式来根据参数输出过滤后的实体 List。我必须检查的一个条件是输入数组参数中的所有条目是否都存在于相关实体中。首先我尝试了:

((inpArray
     .Intersect(x.B.Select(b=>b.CodeID))
     .Count()==inpArray.Count()) 
|| (inpArray.Count() == 0))

这给了我一个例外,说需要在 dbIntersect 中使用可比较的类型。所以我尝试将两者都转换为 Lists,如下所示:

 ((inpList
         .Intersect(x.B.Select(b=>b.CodeID))
         .ToList()
         .Count()==inpList.Count()) 
    || (inpList.Count() == 0))

现在错误

DbExpressionBinding requires an input expression with a collection ResultType.

如何最好地处理问题?

非常感谢。

编辑 以上代码是我需要传递给服务的谓词参数的一部分

尝试分离列表生成:

var list1 = inpArray.ToList();
var list2 = x.B.Select(b => b.CodeID).ToList();


if(list1.Count == 0 || list1.Intersect(list2).Count() == list1.Count)
{
    //Your code
}

试试这个:

!inpArray.Except(x.B.Select(b=>b.CodeID)).Any()