doubt expression Innuendo, clause IN

Asked

Viewed 141 times

1

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 you have on 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" };

need to be returned all cnpj sales from the list. What would this expression look like ?

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 answer

3


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 in my github.

Browser other questions tagged

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