doubt expression linq, clause IN
I have the following expression
retorno = (from ven in context.VendaModel
select new
{
ven.barras,
ven.data,
ven.valor
}).ToList();
I need to search only what I have in a list that will be passed by parameter, for example the following list:
string[] filiais = { "11.111.111/0001-11", "11.111.111/0001-12", "11.111.111/0001-15" };
I need all cnpj sales from the list to be returned. How would that expression look ?
VendaModel Class:
[Table("venda")]
public class VendaModel
{
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id_vendas { get; set; }
public string cpf { get; set; }
public string data { get; set; }
public string hora { get; set; }
public string barras { get; set; }
public string valor { get; set; }
public string qtde { get; set; }
public int cupom { get; set; }
public string cnpj_filial { get; set; }
public string cnpj_matriz { get; set; }
}
1
Author: alessandre martins, 2017-11-25
1 answers
You can make a where
and in it use the Contains
string[] filiais = { "11.111.111/0001-11", "11.111.111/0001-12", "11.111.111/0001-15" };
var retorno = (from ven in context.VendaModel
where filiais.Contains(ven.cnpj_filial)
select new
{
ven.barras,
ven.data,
ven.valor
}).ToList();
If you want, you can see the full example on my GitHub .
3
Author: Pablo Tondolo de Vargas, 2017-11-25 15:31:20