Show null results through the LEFT JOIN with Linq
-
I have a SQL query:
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 = 7341Written in 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")
};I have to show in a Gridview data not recorded, the SQL query returns what I need, but the Linq query, returns the exact opposite.:confused:
-
I have a SQL query:
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 = 7341Written in 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")
};I have to show in a Gridview data not recorded, the SQL query returns what I need, but the Linq query, returns the exact opposite.:confused:
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(new LANCADAs{Data == null})
select new
{
A.Codplano,
A.Secao,
A.Setor,
A.Subsetor,
A.Contato,
Situacao = (B.Subord ?? "N/A")
};something like this will work.