基本信息
源码名称:linq not in 示例源码(not in 不等于 contain(xx)==false)
源码大小:1.16KB
文件格式:.txt
开发语言:C#
更新时间:2014-06-27
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
注意 cotain(xx)=false  在linq中 总是不成立的


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

//Or

Select ProductID, ProductName, CategoryID
From dbo.Products
Where not CategoryID in (1, 2)

//LINQ的IN:

var queryResult = from p in db.Products
where (new int?[] {1,2}).Contains(p.CategoryID)
select p;

//LINQ的IN解析成SQL:

SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued] 
FROM [dbo].[Products]AS [t0]
WHERE [t0].[CategoryID] IN (@p0, @p1)

//LINQ的NOT IN:

var queryResult = from p in db.Products
where ! (new int?[] {1,2}).Contains(p.CategoryID)
select p;

//LINQ的NOT IN解析成SQL:

SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued] 
FROM [dbo].[Products]AS [t0]
WHERE NOT [t0].[CategoryID] IN (@p0, @p1)