entity framework - Linq GroupJoin (join...into) results in INNER JOIN? -


i referencing accepted answer question: linq sql multiple tables left outer join

in example, need of person records regardless if there matching staff record.

i using following query (simplified illustation's sake):

var result = person in context.person                      join staffq in context.staff                          on person.staffid equals staffq.id staffstaffidgroup                      staff in staffstaffidgroup.defaultifempty()                      select new personmodel()                      {                          id = person.id,                          fname = person.fname,                          lname = person.lname,                          sex = person.sex,                          username = staff != null ? staff.username : ""                      }; 

however, contrary expectations, query results in following sql inner join, eliminates records need in the result set.

select  [extent1].[id] [id],  [extent1].[fname] [fname],  [extent1].[lname] [lname],  [extent1].[sex] [sex],  [extent2].[username] [username]  [dbo].[person] [extent1] inner join [dbo].[staff] [extent2] on [extent1].[staffid] = [extent2].[id] 

i thought groupjoin (or join...into) supposed around this? know must have made dumb mistake here, can't see it.

in general query should generate left outer join.

but remember, ef, , has additional information coming model. in case looks staffid property of person enforced fk constraint stuff, ef knows there corresponding record in staff table, hence ignoring left outer join construct , generates inner join instead.

again, model (properties, whether required or not, relationships - required or not etc.) allows ef perform similar smart decisons , optimizations.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -