我想使用 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 };
最佳答案
您应该使用选项 2,即显式调用 AsParallel()
在第二个序列上也是如此。
来自MSDN documentation在 Join
上重载,其中第二个序列的类型为 IEnumerable<TInner>
:
This Join overload should never be called. This method is marked as obsolete and always throws NotSupportedException when invoked.
还要注意声明中的 obsolete-attribute:
[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
)
关于c# - 并行内连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15008415/