apply filter in return from a list

Asked

Viewed 1,454 times

0

I’m making an appointment where I have one array of situations ex: 1, 2, 3 in the query I have to filter through 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 array, grateful to all for your time.

2 answers

2

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

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));

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();
    }
}

Browser other questions tagged

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