Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于二维数组的过滤LINQ到实体查询_C#_Linq_Entity Framework_Linq To Entities - Fatal编程技术网

C# 基于二维数组的过滤LINQ到实体查询

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 + "/" +

这是一个挑战

我有一个实体(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 + "/" + 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();