我试图将DefaultInEmpty()的“ into”语句用于左外部连接,但是当我尝试连接到第三个集合时,它不喜欢它(看不到/使用它/找到)
下面一行似乎不喜欢personRole
join roleTypes in roles on personRole.ContactRoleTypeId equals roleTypes.ContactRoleTypeId into r2
查询:
findPersonResultsViewModelNew =
from azed in findPersonViewModel.findPersonResultsViewModel
join personRole in personContactRoles on azed.PersonID equals personRole.PersonId into r1
join roleTypes in roles on personRole.ContactRoleTypeId equals roleTypes.ContactRoleTypeId into r2
from p in r1.DefaultIfEmpty()
from g in r2.DefaultIfEmpty()
select
//…. other code
答案 0 :(得分:1)
更改语句的顺序。进行左联接时,必须立即在join
之后加上新的from
... DefaultIfEmpty()
:
findPersonResultsViewModelNew =
from azed in findPersonViewModel.findPersonResultsViewModel
join personRole in personContactRoles on azed.PersonID equals personRole.PersonId into prj
from personRole in prj.DefaultIfEmpty()
join roleTypes in roles on personRole.ContactRoleTypeId equals roleTypes.ContactRoleTypeId into rtj
from roleTypes in rtj.DefaultIfEmpty()
select