none
Using PLINQ with Enhancements with Join? RRS feed

  • Question

  • This statement works with LINQPad/LINQ/SQLServer 2014/Northwind):

    from customer in Customers
      join order in Orders on customer.CustomerID equals order.CustomerID
      join detail in OrderDetails on order.OrderID equals detail.OrderID 
      where  order.OrderDate > DateTime.Parse("06/04/1997")  
        & order.OrderDate < DateTime.Parse("07/04/1997")
    select new {cn = customer.CompanyName, o=order.ShipAddress, 
      od=order.OrderDate, d=detail.Product.ProductName}
    

    When I try to use those PLINQ modifiers like "from customer in Customers.AsParallel()" I get syntax errors. Why is this? 

    If I remove the join clauses, then it works:

    from customer in Customers.AsParallel()  select new {cn = customer.CompanyName}

    How do I use PLINQ with the first query that has joins?

    thanks

    Siegfried


    siegfried heintze

    Friday, October 16, 2015 3:36 AM

Answers

  • Hi siegfried_,

    [When I try to use those PLINQ modifiers like "from customer in Customers.AsParallel()" I get syntax errors. Why is this? ]

    After you add AsParallel method for Customers, it return ParallelEnumerable as result. See the join method of ParallelEnumerable.
    https://msdn.microsoft.com/en-sg/library/dd384155(v=vs.110).aspx

    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
    )

    You have to change your code as follow.

    from customer in Customers.AsParallel()
      join order in Orders.AsParallel() on customer.CustomerID equals order.CustomerID
      join detail in OrderDetails.AsParallel() on order.OrderID equals detail.OrderID 
      where  order.OrderDate > DateTime.Parse("06/04/1997")  
        & order.OrderDate < DateTime.Parse("07/04/1997")
    select new {cn = customer.CompanyName, o=order.ShipAddress, 
      od=order.OrderDate, d=detail.Product.ProductName}
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by siegfried_ Wednesday, October 21, 2015 8:16 PM
    Monday, October 19, 2015 3:28 AM
    Moderator

All replies

  • This is the Entity Framework ORM forum that uses Linq  and not a Plinq. You may have better luck with Plinq at Stackoverflow.
    Friday, October 16, 2015 4:03 AM
  • Hi siegfried_,

    [When I try to use those PLINQ modifiers like "from customer in Customers.AsParallel()" I get syntax errors. Why is this? ]

    After you add AsParallel method for Customers, it return ParallelEnumerable as result. See the join method of ParallelEnumerable.
    https://msdn.microsoft.com/en-sg/library/dd384155(v=vs.110).aspx

    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
    )

    You have to change your code as follow.

    from customer in Customers.AsParallel()
      join order in Orders.AsParallel() on customer.CustomerID equals order.CustomerID
      join detail in OrderDetails.AsParallel() on order.OrderID equals detail.OrderID 
      where  order.OrderDate > DateTime.Parse("06/04/1997")  
        & order.OrderDate < DateTime.Parse("07/04/1997")
    select new {cn = customer.CompanyName, o=order.ShipAddress, 
      od=order.OrderDate, d=detail.Product.ProductName}
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by siegfried_ Wednesday, October 21, 2015 8:16 PM
    Monday, October 19, 2015 3:28 AM
    Moderator
  • Li,

    Is there any reason that query does not run with linqpad? I get multiple stack traces when I try that in linqpad where my original (and other) queries run fine in linqpad.

    Thanks

    siegfried


    siegfried heintze

    Monday, October 19, 2015 4:36 PM
  • Li,

    Is there any reason that query does not run with linqpad? I get multiple stack traces when I try that in linqpad where my original (and other) queries run fine in linqpad.

    Thanks

    siegfried


    siegfried heintze

    http://forum.linqpad.net/
    Wednesday, October 21, 2015 2:40 PM