ef左联三张表案例

 users:用户表

Orderss:订单表

U_O:用户和订单的中间表

OrdersEntities1 oe = new OrdersEntities1();
            var result = from user in oe.Users
                         join o_u in oe.U_OC
                         on user.Id equals o_u.UId into o_uList
                         from o_u1 in o_uList.DefaultIfEmpty()
                         join o in oe.Orderss
                         on o_u1.OId equals o.Id into o_u1List
                         from o_u2 in o_u1List.DefaultIfEmpty()
                         select new
                         {
                             user.Name,
                             OrderName=o_u2.Name
                         };

你可能感兴趣的:(案例)