Linq 实现sql中的not in和in条件查询
生活随笔
收集整理的這篇文章主要介紹了
Linq 实现sql中的not in和in条件查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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)
轉載于:https://www.cnblogs.com/qiuguochao/p/6612957.html
總結
以上是生活随笔為你收集整理的Linq 实现sql中的not in和in条件查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html5 excel网页版,一种网页版
- 下一篇: 怎么删除映射网络里的计算机,如何映射网络