Left join in linq is giving error in more than two table

0

I made this link:

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 this line, line is giving this error:

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

This is the error you are giving. I know the task table is already in left . How do I get her to enter another left ?

  

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

    
asked by anonymous 13.06.2014 / 21:32

1 answer

1

I've refined 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();
    
13.06.2014 / 22:20