I want to perform inner join between products and categories with using PLINQ. But I'm not sure if I should call AsParallel method for both collections.
// 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 };
You should use Option 2, i.e. explicitly calling AsParallel() on the second sequence as well.
From the MSDN documentation on the Join overload where the second sequence is of type IEnumerable<TInner> :
This Join overload should never be called. This method is marked as obsolete and always throws NotSupportedException when invoked.
Also note the obsolete-attribute on the declaration:
[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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With