首页 > 代码库 > LINQ 如何实现 in 与 not in
LINQ 如何实现 in 与 not in
T-SQL的IN:Select ProductID, ProductName, CategoryIDFrom dbo.ProductsWhere CategoryID in (1, 2)T-SQL的NOT IN:Select ProductID, ProductName, CategoryIDFrom dbo.ProductsWhere CategoryID not in (1, 2)OrSelect ProductID, ProductName, CategoryIDFrom dbo.ProductsWhere not CategoryID in (1, 2)LINQ的IN:var queryResult = from p in db.Productswhere (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.Productswhere ! (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)
LINQ 如何实现 in 与 not in
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。