Put a decision control inside a lambda expression

2

I'm building this query:

private List<string> pegaInformacaoParceiro(string _osparceiro, string _cnpj)
        {
            List<string> lista = new List<string>();
            WEBEntities db = new WEBEntities();

            var resultado = db.T_PDV
                            .Join(db.T_CRM_StatusPDV, t1 => t1.CNPJ, t2 => t2.DE_Cnpj, (t1, t2) => new { t1, t2 })
                            .Join(db.T_TarefaParceiro, p1 => p1.t1.CNPJ, p2 => p2.CNPJ, (p1, p2) => new { p1, p2 })
                            .Join(db.T_OsParceiro, o1 => o1.p2.IDTarefaParceiro, o2 => o2.IDTarefaParceiro, (o1, o2) => new { o1, o2 })
                            .Join(db.T_Acao, a1 => a1.o1.p2.IDAcao, a2 => a2.IDAcao, (a1, a2) => new { a1, a2 })
                            .Join(db.T_ProximaAcao, x1 => x1.a2.IDAcao, x2 => x2.IDAcao, (x1, x2) => new { x1, x2})
                            .Where(cn => cn.x1.a1.o2.NumOs == Convert.ToInt32(_osparceiro))
                            .Select(i => new { });

            return lista;
        }

I would like _cnpj to be NULL or Empty, to load as it is, otherwise I will do a where with _cnpj and _ospartner. How?

    
asked by anonymous 10.06.2014 / 21:25

1 answer

1

I'm not sure how the comparison with _cnpj is, but I think the line below is pretty close to what you need.

.Where(cn => (cn.x1.a1.o2.NumOs == Convert.ToInt32(_osparceiro)) && (_cnpj == "" || cn.cnpj == _cnpj))
    
10.06.2014 / 21:28