Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# IQueryable可用于多列表比较的位置_C#_Linq_Linq To Sql - Fatal编程技术网

C# IQueryable可用于多列表比较的位置

C# IQueryable可用于多列表比较的位置,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我有一个基本的易趣 private static IQueryable<TestObject> GetFilteredQuery(Guid componentId, Guid productId) { IQueryable<TestObject> query = from t in ModelQuery.Query<TestObject>() where t.Comp

我有一个基本的易趣

private static IQueryable<TestObject> GetFilteredQuery(Guid componentId, Guid productId)
    {
      IQueryable<TestObject> query = from t in ModelQuery.Query<TestObject>()
                                     where t.ComponentId == componentId && t.ProductId == productId
                                     select t;
      return query;
    }
private静态IQueryable GetFilteredQuery(Guid组件ID、Guid产品ID)
{
IQueryable query=来自ModelQuery.query()中的t
其中t.ComponentId==ComponentId&&t.ProductId==ProductId
选择t;
返回查询;
}
如果我必须比较单个组件ID和productId,那么这很简单

我的问题是,当我有一个值对列表时,我该如何处理

Guid[]组件ID,Guid[]产品ID

其中,它是一种键值对

大概

 private static IQueryable<TestObject> GetFilteredQuery(Guid[] componentIds, Guid[] productIds)
    {
      IQueryable<TestObject> query = from t in ModelQuery.Query<TestObject>()
                                     where (t.ComponentId must be present in componentIds[] && t.ProductId must be present in productIds)
                                     select t;
      return query;
    }
私有静态IQueryable GetFilteredQuery(Guid[]组件ID,Guid[]产品ID)
{
IQueryable query=来自ModelQuery.query()中的t
其中(t.ComponentId必须出现在componentIds[]中&t.ProductId必须出现在ProductId中)
选择t;
返回查询;
}
使用:

请注意,由于结果queryable已经具体化,因此它实际上不适合进一步合成。此外,如果您可以在点击此按钮之前进行额外的过滤,这将是有益的。恐怕我还没有实际测试过这一点。

使用:


我不想用它。因为ComponentDS[i]对应于ProductID[i]。如果使用contains(),则会出现不匹配。
 private static IQueryable<TestObject> GetFilteredQuery(Guid[] componentIds, Guid[] productIds)
    {
      IQueryable<TestObject> query = 
         from t in ModelQuery.Query<TestObject>()
         where (componentIds.Contains(t.ComponentId) 
                && productIds.Contains(t.ProductId))
         select t;
      return query;
    }
private static IQueryable<TestObject> GetFilteredQuery(Guid[] componentIds, 
                                                       Guid[] productIds)
{
    var candidates = ModelQuery
         .Query<TestObject>()
         .Where(componentIds.Contains(
                         t.ComponentId) || productIds.Contains(t.ProductId))
         .ToList();// Need to materialize

    var guidPairs = componentIds.Zip(productIds, 
          (c, p) => new {ComponentId = c, ProductId = p});

    return candidates
      .Join(guidPairs, 
            c => new {ComponentId = c.ComponentId, ProductId = c.ProductId}, 
            gp => gp, 
            (c, gp) => c)
      .AsQueryable();
}
where componentIds.Contains(t.ComponentId) && productIds.Contains(t.ProductId)