apply filter on return from a list

0

I'm doing an query where I have a array of situations ex: 1, 2, 3 in the query I have to filter for these situations, follow my code.

var array = GetSituacoes();
var lista = bll.Query(p => p.Contrato.PessoaFisica.ID == SessionControl.PessoaFisica.ID);

I have to filter the list by the situations that are in the array , thankful to everyone for their time.

    
asked by anonymous 17.05.2017 / 16:34

2 answers

1

Hello,

If you are using Dapper you can do it as follows;

string sql = "SELECT * FROM Pessoa WHERE id = @id"
var results = conn.Query(sql, new { id = SessionControl.PessoaFisica.ID });

If you are using EntityFramework you can filter as follows:

public IQueryable<PessoaFisica> GetPessoaFisica(int id)
{
    using(var context = new MyContext()){ 
        return context.PessoaFisica.Where(p => p.id = id).ToList();
    }
}
    
17.05.2017 / 17:07
2

You can use Contains to filter the list according to situations that are in array , like this:

var array = GetSituacoes();
var lista = bll.Query(p => p.Contrato.PessoaFisica.ID == SessionControl.PessoaFisica.ID);
var lista = lista.Where( a => array.Contains(a.Contrato.Situacoes));
    
17.05.2017 / 17:17