need a simple linq
I have a table called products. I want to get all products that 开发者_StackOverflow社区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
from p in Products
where new int [] { 2,6,9 }.Contains(p.ProductID)
select p;
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)
精彩评论