How do I perform a Left Outer Join in Linq?
本问题已经有最佳答案,请猛点这里访问。
我刚接触Linq,需要将此查询转换为DocumentStores和订单之间的左外部联接,因为并非所有文档都与订单相关:
1 2 3 4 5 6 7 8 9 10 11 | 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(); |
我如何做到这一点?
1 2 3 4 | 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> |
如果ID上的联接失败,b将为空。