1
I have two entities (TipoDeRequerimento
and TipoRequerimentoSituaçãoAcademica
) in my query. Today I can make a filter to bring the Types of requirements that have a certain academic situation pre-registered. Now I need this filter to return also the requirements types that do not have Academic Situation informed, that is, for a certain requirement that I registered and did not inform Academic Situation.
Follow the code of the consultation:
IList lista = null;
using (var bll = new TipoRequerimentoRepository(empresa))
{
var pLista = bll.Query(p => p.Descricao.Contains(filtro) || filtro == "")
.Where(p => categoriaID == 0 || p.CategoriaID == categoriaID)
.Where(p => situacaoAcademicaID == 0 || p.TipoRequerimentoSituacaoAcademica.Any(x => x.AlunoSituacaoAcademica.AlunoSituacaoAcademicaID == situacaoAcademicaID))
.Where(p => p.Ativo == true)
.Select(p => new
{
id = p.ID,
name = p.Descricao,
prazoDias = p.Prazo,
valor = p.ValorUnitario,
Gratuito = p.Gratuito
});
lista = pQtdeRegistros > 0 ? pLista.Take(pQtdeRegistros).AsNoTracking().Distinct().ToList() : pLista.AsNoTracking().ToList();
}
return lista;
In the filter I tried to put a code that filtered the TipoRequerimentoStuacaoAcademica == NULL
but I did not succeed. If someone can help me, I really appreciate.
I also tried it returns empty with nothing on the list
– Thiago Ubiratan
It worked with a help of a parentheses getting that way
.Where(p => (!p.TipoRequerimentoSituacaoAcademica.Any() || p.TipoRequerimentoSituacaoAcademica.Any(x => x.AlunoSituacaoAcademica.AlunoSituacaoAcademicaID == situacaoAcademicaID)))
– Thiago Ubiratan