LEFT OUTER JOIN in LINQ

后端 未结 22 2552
臣服心动
臣服心动 2020-11-21 04:49

How to perform left outer join in C# LINQ to objects without using join-on-equals-into clauses? Is there any way to do that with where clause? Corr

22条回答
  •  猫巷女王i
    2020-11-21 05:38

    (from a in db.Assignments
         join b in db.Deliveryboys on a.AssignTo equals b.EmployeeId  
    
         //from d in eGroup.DefaultIfEmpty()
         join  c in  db.Deliveryboys on a.DeliverTo equals c.EmployeeId into eGroup2
         from e in eGroup2.DefaultIfEmpty()
         where (a.Collected == false)
         select new
         {
             OrderId = a.OrderId,
             DeliveryBoyID = a.AssignTo,
             AssignedBoyName = b.Name,
             Assigndate = a.Assigndate,
             Collected = a.Collected,
             CollectedDate = a.CollectedDate,
             CollectionBagNo = a.CollectionBagNo,
             DeliverTo = e == null ? "Null" : e.Name,
             DeliverDate = a.DeliverDate,
             DeliverBagNo = a.DeliverBagNo,
             Delivered = a.Delivered
    
         });
    

提交回复
热议问题