开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜