C# 基于二维数组的过滤LINQ到实体查询
这是一个挑战 我有一个实体(ID、CategoryID、Value)和一个带有CategoryID/Value对的二维int数组。我需要将所有实体按每对进行筛选,例如:C# 基于二维数组的过滤LINQ到实体查询,c#,linq,entity-framework,linq-to-entities,C#,Linq,Entity Framework,Linq To Entities,这是一个挑战 我有一个实体(ID、CategoryID、Value)和一个带有CategoryID/Value对的二维int数组。我需要将所有实体按每对进行筛选,例如: from e in Entity where (e.CategoryID and e.Value) in array select e; 所以基本上是一个“两个链接字段”过滤器 一个肮脏的解决方案是收集和比较,如: concatarray = some function to concat CategoryID + "/" +
from e in Entity
where (e.CategoryID and e.Value) in array
select e;
所以基本上是一个“两个链接字段”过滤器
一个肮脏的解决方案是收集和比较,如:
concatarray = some function to concat CategoryID + "/" + Value;
from e in Entity
where e.CategoryID + "/" + e.Value in concatarray
select e;
但由于性能问题,我不想使用它
有什么想法吗
非常感谢 首先,我将把数组转换为具有特定属性的对象列表。为此使用2d数组不是一个好主意 那么,查询可能无法在EF中转换为SQL
from e in Entity
where array.Where(a=>a.CategoryID == e.CategoryID && a.Value == e.Value).Any()
select e
首先,我将把数组转换成具有特定属性的对象列表。为此使用2d数组不是一个好主意 那么,查询可能无法在EF中转换为SQL
from e in Entity
where array.Where(a=>a.CategoryID == e.CategoryID && a.Value == e.Value).Any()
select e
+1但为了简洁起见,更喜欢.Any(a=>a.CategoryID==e.CategoryID&&a.Value==e.Value)
。不起作用的家伙:“无法创建'GEO.Data.CategoryAttributeValue'类型的常量值。只有基本类型…”列表属性=新列表();Add(新CategoryAttributeValue{CategoryAttributeID=1,Value=1});var queryAttributes=从db.CategoryAttributeValues where attributes.where中的a开始(av=>av.CategoryAttributeID==a.CategoryAttributeID)。Any()选择a;queryAttributes.ToList()+1但为了简洁起见,更喜欢.Any(a=>a.CategoryID==e.CategoryID&&a.Value==e.Value)
。不起作用的家伙:“无法创建'GEO.Data.CategoryAttributeValue'类型的常量值。只有基本类型…”列表属性=新列表();Add(新CategoryAttributeValue{CategoryAttributeID=1,Value=1});var queryAttributes=从db.CategoryAttributeValues where attributes.where中的a开始(av=>av.CategoryAttributeID==a.CategoryAttributeID)。Any()选择a;queryAttributes.ToList();