0
var query = from section in load_sections.Sections
            join course in load_sections.Courses
                on section.Course_Id equals course.Course_Id
            join faculty in load_sections.Faculties
                on section.Faculty_Id equals faculty.Faculty_Id
            select section;

我的 section.Faculty_Id 中有一些空值,它们不等于 Faculty.Faculty_Id 中的任何行,它只是返回 section.Faculty_Id 不为空的记录...如果 section.Faculty_Id 不为空,那么它必须返回 Table Courses 的其他剩余字段

4

1 回答 1

2

如果faculty由于某种原因无法删除连接,则必须构造一个外部连接:

var query = from section in load_sections.Sections
            join course in load_sections.Courses
                on section.Course_Id equals course.Course_Id
            join faculty in load_sections.Faculties
                on section.Faculty_Id equals faculty.Faculty_Id into faculties
            from f in faculties.DefaultIfEmpty()
            select section;

这执行一个GroupJoinwith Faculties。随后的效果from f in faculties是分组再次被 a 展平SelectMany.DefaultIfEmpty()创建外连接。

于 2013-04-04T20:39:35.227 回答