简体   繁体   English

实体框架中的空值

[英]Null Values in Entity Framework

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;

I have some null values in my section.Faculty_Id which will not be equal to any row in faculty.Faculty_Id and it is just returning the records where section.Faculty_Id is not null...If section.Faculty_Id is not null, then it must return the other remaining fields of Table Courses 我的section.Faculty_Id中有一些空值,它们不等于faculty.Faculty_Id中的任何行,它只是返回section.Faculty_Id不为null的记录...如果section.Faculty_Id不为null,那么它必须返回表课程的其他剩余字段

If you can't drop the join on faculty for whatever reason, you'll have to construct an outer join: 如果由于某种原因你不能放弃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;

This executes a GroupJoin with Faculties . 该执行GroupJoinFaculties The effect of the subsequent from f in faculties is that the grouping is flattened again by a SelectMany . 随后from f in faculties是由SelectMany再次使分组变平。 .DefaultIfEmpty() creates the outer join. .DefaultIfEmpty()创建外连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM