Ghooti Farangi
Ghooti Farangi

Reputation: 20156

need a simple linq

I have a table called products. I want to get all products that have productID 2 OR 6 OR 9 the SQL is : Select * from products where productID=2 OR productID=6 OR ProductID=9. How can I do this sql by LINQ? The productIds are in an array

Upvotes: 2

Views: 55

Answers (2)

Mark Cidade
Mark Cidade

Reputation: 99957

var q = from p in Products
        where p.productID==2 || p.productID==6 || p.productID==9
        select p;

foreach(var product in q)
{
  //...
}

or simply:

db.Products.Where(p=> p.productID==2 || p.productID==6 || p.productID==9)

Upvotes: 1

leppie
leppie

Reputation: 117250

from p in Products
where new int [] { 2,6,9 }.Contains(p.ProductID)
select p;

Upvotes: 2

Related Questions