Linq Return all records when ID is NULL

Asked

Viewed 113 times

1

Consultation:

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 which case I would like to return all records, which I must adjust?

  • alessandre made a modification that I believe will improve the understanding of your question. if you do not agree let me know what return as it was :)

1 answer

1


see if he answers 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);

Browser other questions tagged

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