Filtering for empty children

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 also return the Application Types that do not have an Academic Status informed, that is, for a given application that I have registered and did not report Academic Status.

Follow the query code:

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 TipoRequerimentoStuacaoAcademica == NULL but did not succeed. If anyone can help me, thank you very much.

    
asked by anonymous 04.10.2017 / 02:23

2 answers

1

If, for example, we define that situacaoAcademicaID = -1 returns the requirements that do not have Academic Status informed, you can implement this:

var pLista = bll.Query(p => p.Descricao.Contains(filtro) || filtro == "")
    .Where(p => categoriaID == 0 || p.CategoriaID == categoriaID)
    .Where(p => situacaoAcademicaID == 0
                || situacaoAcademicaID == -1 && p.TipoRequerimentoSituacaoAcademica.Count == 0 
                || p.TipoRequerimentoSituacaoAcademica.Any(x => x.AlunoSituacaoAcademica.AlunoSituacaoAcademicaID == situacaoAcademicaID))
    .Where(p => p.Ativo == true)
    .Select(p => new
    
04.10.2017 / 05:01
3

It seems like TipoRequerimentoStuacaoAcademica is a collection of TipoDeRequerimento .

Try to use !p.TipoRequerimentoStuacaoAcademica.Any() instead of p.TipoRequerimentoStuacaoAcademica == null .

    
04.10.2017 / 02:31