我有一个SQL查询:
SELECT A.Codplano, A.Secao, A.Setor,A.Subsetor,A.Contato, ISNULL(B.Subord,'NÃO
LANÇADA')AS Situacao
FROM vwPLANODIN A LEFT JOIN LANCADA B
ON A.Codplano = B.Subord
and B.Data = '2014-06-10'
WHERE B.ID IS NULL and A.Sitio = 7341
写在Linq:
var cob = from A in dataClass.vwPLANODINs
join B in dataClass.LANCADAs on new { A.Codplano, Data = data }
equals new { Codplano = B.Subord, Data = Convert.ToString(B.Data) } into B_join
from B in B_join.DefaultIfEmpty()
where
B.Data == null &&
A.Sitio == local
select new
{
A.Codplano,
A.Secao,
A.Setor,
A.Subsetor,
A.Contato,
Situacao = (B.Subord ?? "N/A")
};
我必须在未记录的Gridview数据中显示,SQL查询返回我需要的内容,但Linq查询返回的恰恰相反。
答案 0 :(得分:0)
我不会使用outer join
,而是一个解析为not exists
的查询:
var cob = from A in dataClass.vwPLANODINs
where !(from B in dataClass.LANCADAs
where B.Subord == A.Codplano && B.Data == data
select B)
.Any()
&& A.Sitio == local
select new
{
A.Codplano,
A.Secao,
A.Setor,
A.Subsetor,
A.Contato,
Situacao = (B.Subord ?? "N/A")
};