比较LinqToEntity查询中的EntityCollection <class> </class>

时间:2012-04-23 09:16:08

标签: c# .net linq-to-entities compare entitycollection

是否可以比较Linq查询中的两个EntityCollection?

我试过这种方式:

from t in _bdd.Table
where (idList).All(id=>  t.ids.Contains(id))
                         select i).FirstOrDefault()

其中idList和ids都是EntityCollection

但是我得到了一个N​​otSupportedException:

"Unable to create a constant value of type (ID) Only primitive types ('such as Int32, String, and Guid') are supported in this context"

是否无法在单个Linq查询中比较两个List?

1 个答案:

答案 0 :(得分:0)

首先,异常是由使用本地集合(idList)作为where子句中的源引起的。相反,你应该尝试切换侧面,以便它显示在右侧可能在一些LINQ方法内。

我认为这可以让查询获得您想要的结果:

where t.ids.Count() == idList.Count() && t.ids.All(ids => idList.Contains(id))

“选择i”部分也不清楚它的选择。您的代码段中没有名为i的变量。