Linq 的 in (转载,为自己所用)

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)

posted @ 2012-10-09 11:34  Timmy-1988  阅读(168)  评论(0编辑  收藏  举报