Left Join LINQ equivalent

10/19/2010 8:21:30 PM

A left join in L2S. Also replacing missing joined table column null values with -1 to fulfill type requirements (int can't be null).

var query = from c in  db.Customers    join ojc in db.Orders on c.CustomerID equals ojc.CustomerID into oj   from o in oj.DefaultIfEmpty()   select new {    CustomerID = c.CustomerID,    ContactName = c.ContactName,    OrderID = x.OrderID == null ? -1 :  x.OrderID   };  

The last row, orderid mapping, is necessary due to customers with no orders will have a null value thats not allowed for the inferred integer type.