EF 左联合

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 左联合)