zoukankan      html  css  js  c++  java
  • 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)
    

      

  • 相关阅读:
    iOS7,iOS8和iOS9的区别
    NSUrl
    什么是 MIME TYPE?
    TCP协议与UDP协议的区别
    KVC、KVO、NSNotification、delegate 总结及区别
    cocoapods 安装过程及常见问题
    素材丶资料
    方法 笔记(二)
    UIWebView UITextView
    在oj中Python的循环输入问题解决
  • 原文地址:https://www.cnblogs.com/qiuguochao/p/6612957.html
Copyright © 2011-2022 走看看