c# - 使用多个带有 into 的 LINQ 语句,因为左外连接的 DefaultIfEmpty() 不起作用
问题描述
我正在尝试使用带有 DefaultIfEmpty() 的“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
解决方案
改变你的陈述的顺序。进行左连接时,您必须立即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
推荐阅读
- python - 将图像合并到 z-stack 中并在 Python 中进行最大投影 /
- javascript - 如何将数据导入到 gatbsy-config.js
- python - 如何修复所需的位置参数?
- php - 在 WP Shortcode 中显示来自 mySQL 的数据字段
- r - 'Sum' 函数返回 TRUE 或 FALSE 值而不是数字?
- spring - 更新现有 elasticsearch 实例的集群名称
- ios - UIApplicationDelegate 如何强制其“window”为“internal”而不是“private”,但是当名称更改为“door”时可以吗?
- python - 从另一个数组更新 numpy 2d 数组索引
- reactjs - 如何在 useEffect 挂钩中形成 setFieldValue
- python - 将列一一添加到新的 DataFrame