【问题标题】:Parallel inner join并行内连接
【发布时间】:2013-02-21 17:19:10
【问题描述】:

我想使用 PLINQ 在产品和类别之间执行内部连接。但我不确定是否应该为这两个集合调用 AsParallel 方法。

// PLINQ  - Option 1
jointTables =     from c in Homework02.categories.AsParallel()
                  join p in Homework02.productList on c.Name equals p.Category
                  select new { Category = c, Product = p };

// PLINQ  - Option 2
jointTables = from c in Homework02.categories.AsParallel()
              join p in Homework02.productList.AsParallel() on c.Name equals p.Category
              select new { Category = c, Product = p };

【问题讨论】:

    标签: c# linq plinq parallel-extensions


    【解决方案1】:

    您应该使用选项 2,即在第二个序列上也显式调用 AsParallel()

    Join 重载上的MSDN documentation 开始,其中第二个序列的类型为IEnumerable<TInner>

    永远不应调用此 Join 重载。 此方法标记为 已过时并且在调用时总是抛出 NotSupportedException。

    还要注意声明中的过时属性:

    [ObsoleteAttribute(@"The second data source of a binary operator 
                        must be of type System.Linq.ParallelQuery<T> 
                        rather than System.Collections.Generic.IEnumerable<T>. 
                        To fix this problem, use the AsParallel() extension
                        method to convert the right data source to
                        System.Linq.ParallelQuery<T>.")]
    public static ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(
        this ParallelQuery<TOuter> outer,
        IEnumerable<TInner> inner,
        Func<TOuter, TKey> outerKeySelector,
        Func<TInner, TKey> innerKeySelector,
        Func<TOuter, TInner, TResult> resultSelector
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 2010-09-10
      • 1970-01-01
      • 2013-05-28
      • 2011-06-23
      • 1970-01-01
      相关资源
      最近更新 更多