Good morning, guys, I'm in need of help with LINQ. I'm trying to perform the following query through linq:
SELECT NFE_SAIDA.NFESAI_SEQUENCIA
FROM CAD_NFE_SAIDA NFE_SAIDA
LEFT JOIN CAD_NFE_SAIDA_ESTACOES NFE_SAIDA_ESTACOES ON NFE_SAIDA.NFESAI_SEQUENCIA = NFE_SAIDA_ESTACOES.NFESAI_SEQUENCIA AND
NFE_SAIDA_ESTACOES.EST_SEQUENCIA = 2 AND
NFE_SAIDA_ESTACOES.NFESAIEST_SINCRONIZADO = 'S'
WHERE NFE_SAIDA.EMP_SEQUENCIA = 1
AND NFE_SAIDA_ESTACOES.NFESAIEST_SEQUENCIA IS NULL
In summary, I need all items in the A(CAD_NFE_SAIDA)
table when its LEFT
with the B(CAD_NFE_SAIDA_ESTACOES) (Da EST_SEQUENCIA = 2 , e SINCRONIZADOS = 'S')
not satisfied.
So I'll get the ID of all the notes that have not yet been synced to that station.
I tried the following:
var query = (from _NFESAIDA in _contexto.NfeSaida.Where(_C => _C.EmpSequencia == empSequencia)
join _NFESAIDA_ESTACAO in _contexto.NfeSaidaEstacao on _NFESAIDA.NfesaiSequencia equals _NFESAIDA_ESTACAO.NfesaiSequencia into _a
from _NFESAIDA_ESTACAO in _a.DefaultIfEmpty()
.Where(_A => _A.NfesaiSincronizado != "S").DefaultIfEmpty().Where(_A => _A.EstSequencia == estSequencia).DefaultIfEmpty()
select new ObjSequenciaNota {
Sequencia = _NFESAIDA.NfesaiSequencia}
);
return query;
However, linq does an INNER join with table 'B' which invalidates my query.
Any help?