左连接LINQ to SQL

时间:2010-08-23 21:25:40

标签: 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

目前,这是“错误”和“项目”之间的内部联接。如何将其变为左连接?

1 个答案:

答案 0 :(得分:0)

我没有对此进行过测试,但下面的查询可以让您朝着正确的方向前进。关键是join ... into语法和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
}