对in使用多个LINQ语句,以使左外部联接的DefaultIfEmpty()不起作用 [英] Using multiple LINQ statements with into , for the DefaultIfEmpty() of the left outer join not working

查看:58
本文介绍了对in使用多个LINQ语句,以使左外部联接的DefaultIfEmpty()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将DefaultInEmpty()的"into"语句用于左外部连接,但是当我尝试连接到第三个集合时,它不喜欢它(看不到/使用它/查找)

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 )

在下面的行中似乎不喜欢personRole

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

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 

推荐答案

更改语句的顺序.进行左联接时,必须立即在join之后加上新的from ... DefaultIfEmpty():

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

这篇关于对in使用多个LINQ语句,以使左外部联接的DefaultIfEmpty()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆