【发布时间】:2019-04-10 13:08:58
【问题描述】:
我在 linq 查询中使用左连接。我需要检查 ON 子句中的左表值是否为空。
join x in employeee on u.id equals x.userId into ux
from ujoinx in ux.DefaultIfEmpty()
join y in department on ujoinx.id equals y.employeeId into xy
from xjoiny in xy.DefaultIfEmpty()
select new {
EmployeeSal = ujoinx!=null?ujoinx.employeeSal:0,
EmployeeTax = ujoinx!=null?ujoinx.employeeTax:0,
UserName = u.username,
DeptName = xjoiny!=null?xjoiny.name:""
}
这里我要检查 ujoinx 在这个连接条件下是否为空。 join y in department on ujoinx.id equals y.employeeId into xy。
有没有可能用ujoinx.id equals y.employeeId检查空条件?
【问题讨论】:
-
为什么不在连接前添加 where 子句?
-
我试过
join y in department where ujoinx != null on ujoinx.id equals y.employeeId into xy。它不工作 -
有什么解决办法吗?