加入左LINQ to SQL中
问题描述:
这是我的查询:加入左LINQ to SQL中
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
目前这样做“错误”和“项目”之间的内部连接。我如何将它变成左连接?
答
我还没有测试过这个,但下面的查询应该让你朝着正确的方向前进。关键是将...加入语法并使用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
}