Left Join on the Linq is giving error in more than two tables

Asked

Viewed 309 times

0

I did that last breath:

var resultado = (
    from pdv in db.T_PDV
    join tarefa in db.T_TarefaParceiro on pdv.CNPJ equals (tarefa.CNPJ) into _trf
    from g1 in _trf.DefaultIfEmpty()
    join parceiro in db.T_OsParceiro on tarefa.IDTarefaParceiro equals (parceiro.IDTarefaParceiro) into _pcr
    from g2 in _pcr.DefaultIfEmpty()
    join acao in db.T_Acao on tarefa.IDAcao equals (acao.IDAcao) into _acao
    from g3 in _acao.DefaultIfEmpty()
    join proxima in db.T_ProximaAcao on acao.IDAcao equals (proxima.IDAcao) into _pxm
    from g4 in _pxm.DefaultIfEmpty()
    join info in db.T_InfoClientePdv on pdv.CNPJ equals (info.CNPJ) into _info
    from g5 in _info.DefaultIfEmpty()
    join cliente in db.T_Cliente on info.IDCliente equals (cliente.IDCliente) into _clie
    from g6 in _clie.DefaultIfEmpty()

    select new
    {
        pdv.CNPJ,
        pdv.DataCadastro,
        cliente.NomeFantasia,
        acao.Acao,
        proxima.ProximaAcao,
        parceiro.NumOs,
        parceiro.DataVisita,
        parceiro.DataAgendamento
    }).ToList();

On that line is making that mistake:

join parceiro in db.T_OsParceiro on tarefa.IDTarefaParceiro equals (parceiro.IDTarefaParceiro) into _pcr

This is the error that is giving. I know that the task table, is already in left. How do I get her back into another left?

The name 'task' is not in Scope on the left side of 'equals'. Consider swapping the Expressions on either side of 'equals'.

1 answer

1

I remade my LINQ and now it worked. I did so:

var resultado = (
    from pdv in db.T_PDV
    from tarefa in db.T_TarefaParceiro.Where(trf => trf.CNPJ == pdv.CNPJ).DefaultIfEmpty()
    from parceiro in db.T_OsParceiro.Where(prf => prf.IDTarefaParceiro == tarefa.IDTarefaParceiro)
    from acao in db.T_Acao.Where(ac => ac.IDAcao == tarefa.IDAcao).DefaultIfEmpty()
    from proxima in db.T_ProximaAcao.Where(pxm => pxm.IDAcao == acao.IDAcao).DefaultIfEmpty()
    from info in db.T_InfoClientePdv.Where(inf => inf.CNPJ == pdv.CNPJ).DefaultIfEmpty()
    from cliente in db.T_Cliente.Where(clie => clie.IDCliente == info.IDCliente).DefaultIfEmpty()

    select new
    {
        pdv.CNPJ,
        pdv.DataCadastro,
        cliente.NomeFantasia,
        acao.Acao,
        proxima.ProximaAcao,
        parceiro.NumOs,
        parceiro.DataVisita,
        parceiro.DataAgendamento
    }).ToList();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.