Linq Return all records when ID is NULL

1

Inquiry:

retorno = tarefaRep.GetAll(c => c.status == 0
                                  && c.id_empresa == idEmpresa
                                  && c.id_cliente.ToString().Equals(idCliente)
                                  && c.id_colaborador.ToString().Equals(idColaborador),
                                 limit, ctx);

idCliente and idColaborador can be null, in this case I would like to return all records, what should I adjust?

    
asked by anonymous 16.08.2017 / 22:29

1 answer

1

see if it suits you:

retorno = tarefaRep.GetAll(c => c.status == 0
                              && c.id_empresa == idEmpresa
                              && (idCliente == null ? true : c.id_cliente.ToString().Contains(idCliente))
                              && (idColaborador == null ? true : c.id_colaborador.ToString().Contains(idColaborador)),
                             limit, ctx);
    
16.08.2017 / 22:39