[英]Compare EntityCollection<Class> in a LinqToEntity query
是否可以在Linq查詢中比較兩個EntityCollection?
我這樣嘗試:
from t in _bdd.Table
where (idList).All(id=> t.ids.Contains(id))
select i).FirstOrDefault()
其中idList和id都是EntityCollection
但是我得到了NotSupportedException:
"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?
首先,異常是由於在where子句中使用本地集合(idList)作為源而引起的。 相反,您應該嘗試切換它的側面,以便它出現在右側可能在某些LINQ方法內部。
我認為這在哪里查詢將為您提供所需的結果:
where t.ids.Count() == idList.Count() && t.ids.All(ids => idList.Contains(id))
另外,“選擇我”部分還不清楚選擇什么。 您的代碼段中沒有變量i。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.