LINQ TO SQL中NOT IN怎么使用
1个回答
展开全部
T-SQL的 IN:
Select ProductID, ProductName, CategoryID
From dbo.Products
Where CategoryID in (1, 2)
T-SQL的 NOT IN:
Select ProductID, ProductName, CategoryID
From dbo.Products
Where CategoryID not in (1, 2)
//--------------------------------------------------------
LINQ的 IN:
var queryResult = from p in db.Products
where (new int?[] {1,2}).Contains(p.CategoryID)
select p;
LINQ的 NOT IN:
var queryResult = from p in db.Products
where ! (new int?[] {1,2}).Contains(p.CategoryID)
select p;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询