Hoody
Hoody

Reputation: 3381

Linq outer Join

How do I change this query to an outer join so that customers with no orders still appear in the results?

Customers
                   .Join(
                      Orders,
                      c => c.ID,
                      r => r.ID,
                      (c, r) =>
                         new
                         {
                             Name = c.Name,
                             Address = c.Address,
                             OrderNumber = r.OrderNumber,
                             OrderDetails = r.OrderDetails
                         }
                   ).ToList()

Upvotes: 0

Views: 888

Answers (1)

Pravin Pawar
Pravin Pawar

Reputation: 2569

from c in context.Customers     
join o in context.order on new { cid = c.cid } equals new { cid = o.cid } into ljoin
from l in ljoin.DefaultIfEmpty()
select new()
{
  //whatever
};

Upvotes: 3

Related Questions