0

I am new to Linq, and I need to convert this query to a left outer join between DocumentStores and Orders, as not all documents are related to an order:

    var documents=(from d in _dataContextOrders .DocumentStores 
                           join o in _dataContextOrders.Orders on d.OrderID equals o.ID
                           join t in _dataContextOrders .DocumentTypes on d.DocumentType equals t.DocTypeID
                       select new
                           {
                               d.ID,
                               o.PORef ,
                               t.DocTypeDescription,
                               d.Name,
                               d.ContentType
                           }).ToList();

How do I achieve this?

Calum
  • 1,809
  • 2
  • 19
  • 35
Steve Staple
  • 2,622
  • 7
  • 30
  • 64

1 Answers1

1
from a in dataContext.<tableA>
join _b in dataContext.<tableB> on a.id equals _b.aid into _b
from b in _b.DefaultIfEmpty()
select <whatyouwanttoselect>

b will be null, if the join on the ids fails

schlonzo
  • 1,401
  • 12
  • 14