Using multiple LINQ statements with into , for the

2019-08-22 09:45发布

I am trying to use the "into" statement with DefaultIfEmpty() for the left outer join, but when I try to join to the 3rd collection, it doesn't like it (can't see /use it / find it )

It doesn't seem to like personRole on the line below

join roleTypes in roles on personRole.ContactRoleTypeId equals roleTypes.ContactRoleTypeId into r2

the query:

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 

1条回答
Melony?
2楼-- · 2019-08-22 10:29

Change the order of your statements. When doing left join, you must immediately follow the join with a new 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
查看更多
登录 后发表回答