3

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 };
svick
  • 236,525
  • 50
  • 385
  • 514

1 Answers1

5

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
)
Ani
  • 111,048
  • 26
  • 262
  • 307