Linq join with an inner collection

Posted by bronze on Stack Overflow See other posts from Stack Overflow or by bronze
Published on 2010-03-23T06:19:55Z Indexed on 2010/03/23 6:23 UTC
Read the original article Hit count: 380

Filed under:
|
|

Hi,

I am trying a LINQ to Object query on 2 collections

  1. Customer.Orders
  2. Branches.Pending.Orders (Collection within a collection)

I want to output each branch which is yet to deliver any order of the customer.

var match = from order in customer.Orders 
    join branch in Branches 
    on order equals branch.Pending.Orders 
    select branch;

This does not work, I get : The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.

From my search, I think this is because Order or collection of Orders does not implement equals.

If this query worked, it will still be wrong, as it will return a branch if the customer's and pending orders match exactly. I want a result if any of the order matches.

I am learning Linq, and looking for a approach to address such issues, rather than the solution itself.

I would have done this in SQL like this;

SELECT b.branch_name from Customers c, Branches b, Orders o
WHERE c.customer_id = o.customer_id
  AND o.branch_id = b.branch_id
  AND c.customer_id = 'my customer'
  AND o.order_status = 'pending'

© Stack Overflow or respective owner

Related posts about linq-to-objects

Related posts about LINQ