0

I need to pass an enumerated list and get only the records that have the "Application" field equivalent to the one in the enumerated list, according to the sql described below:

select * from "FormaContato" as "fc"
inner join "FormaContatoAplicacao" as "fca" ON "fc"."Id" = "fca"."FormaContatoId"
where "fca"."AplicacaoId" in (2, 1, ...)

public enum AplicacaoEnum
{
    [Description("PESSOA FÍSICA")]
    Nenhum = 1,
    [Description("PESSOA JURÍDICA")]
    ContatoTelefonico = 2
}

public IQueryable<FormaContato> GetAllByAplicacao(List<AplicacaoEnum> aplicacaoList = null)
{
    var data = DbSet.
        Include(x => x.FormaContatoAplicacoes)
        .Where(x=> x.FormaContatoAplicacoes.Aplicacao == aplicacaoList ????????? Here.)
        .AsNoTracking();

    return data;
        
}

How to do this? Thanks! :)

devlin carnate
  • 8,309
  • 7
  • 48
  • 82
masterj
  • 67
  • 6
  • Does this answer your question? [Linq select objects in list where exists IN (A,B,C)](https://stackoverflow.com/questions/14257360/linq-select-objects-in-list-where-exists-in-a-b-c) – devlin carnate Oct 20 '21 at 19:46

1 Answers1

0

It seems like you are looking for the .Contains() method.

So in your case it would be something like:

var data = DbSet
     .Include(x => x.FormaContatoAplicacoes)
     .Where(x=> aplicacaoList.Contains(x.FormaContatoAplicacoes.Aplicacao))
     .AsNoTracking();

Also please notice that if you are not about to use FormaContatoAplicacoes later in your flow, I see no reason to use the .Include() here.

Tom Carmi
  • 385
  • 1
  • 5
  • 18