我有以下SQL,我正在try 将其转换为LINQ:
SELECT f.value
FROM period as p
LEFT OUTER JOIN facts AS f ON p.id = f.periodid AND f.otherid = 17
WHERE p.companyid = 100
我见过左外连接的典型实现(如into x from y in x.DefaultIfEmpty()
等),但不确定如何引入其他连接条件(AND f.otherid = 17
)
EDIT
为什么AND f.otherid = 17
条件是JOIN的一部分,而不是WHERE子句的一部分?
不幸的是:
from p in context.Periods
join f in context.Facts on p.id equals f.periodid into fg
from fgi in fg.DefaultIfEmpty()
where p.companyid == 100 && fgi.otherid == 17
select f.value
似乎相当于:
SELECT f.value
FROM period as p
LEFT OUTER JOIN facts AS f ON p.id = f.periodid
WHERE p.companyid = 100 AND f.otherid = 17
这不是我想要的.