开发者

Left joins in LINQ to SQL

T开发者_运维问答his is my query:

Dim bugs = (From b In bugCon.bugs Where sctUserIds.Contains(b.Developer.Value) Order By b.bg_id Select Bug = b, Project = b.project).ToList

Currently this does an inner join between "bugs" and "projects". How do I turn it into a left join?


I haven't tested this, but the query below should get you headed in the right direction. The key is the join ... into syntax and the use of DefaultIfEmpty()

from b in context.Bugs
join p in context.Projects
on b.projectID equals p.projectID into BugProjects
where sctUserIds.Contains(b.Developer.Value)
from bugProjects in BugProjects.DefaultIfEmpty()
select new {
  Name = p.Name,
  ...
  BugProjects = bugProjects
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜