码迷,mamicode.com
首页 > 其他好文 > 详细

EF 左联合

时间:2020-02-16 01:15:26      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:sele   lambda   list()   use   als   otto   audit   class   pre   

Lambda

  var q1 = db.IntelligenceTable.Where(x => x.IsUsable == 0).GroupJoin(db.Users, x => x.Publisher, y => y.id,
                (x, y) => new { x, PName = y.FirstOrDefault().Name }).GroupJoin(db.Users, x => x.x.Auditor, y => y.id,
                (x, y) => new { x.x.id, x.x.Contents, x.PName, AName = y.FirstOrDefault().Name }).ToList();

Linq

   var q2 = (from i in db.IntelligenceTable
                      join pu in db.Users on i.Publisher equals pu.id into pui
                      from pu in pui.DefaultIfEmpty()
                      join pa in db.Users on i.Auditor equals pa.id into pai
                      from pa in pai.DefaultIfEmpty()
                      select new
                      {
                          i.id,
                          i.Contents,
                          Pn = pu.Name,
                          Pa = pa.Name
                      }).ToList();

ps:三联合(主) IntelligenceTable (从)Users 

pss:自用的

 

EF 左联合

标签:sele   lambda   list()   use   als   otto   audit   class   pre   

原文地址:https://www.cnblogs.com/xianyv/p/11888387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!