EF 左联合
Posted xianyv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 左联合的主要内容,如果未能解决你的问题,请参考以下文章