我正在尝试进行可以加入可能的空值的连接。
from data in Data
join d1 in Data on new { a = data.pId, b = language } equals new { a = d1.pId, b = d1.language } into j1
from dta1 in j1.DefaultIfEmpty()
join d2 in Data on new { a = data.pId, b = fallback} equals new { a = d2.pId, b = d2.language } into j2
from dta2 in j1.DefaultIfEmpty()
where ((int?)dta1.id ?? dta2.id) == data.Id
select data;
这里的问题是pId可以为null,如果是,则连接在比较时将不匹配
data.pId = null
而不是
data.pId is null
在正常的where子句中,我可以执行object.Equals(data.pId,d1.pId)并且它会进行空检查,但是如何在连接中执行此操作?
答案 0 :(得分:0)
一种方法是将空值转换为其他一些未使用但相等的值。
join d1 in Data
on new { a = data.pId ?? -33, b = language }
equals new { a = d1.pId ?? -33, b = d1.language }
into j1