zoukankan      html  css  js  c++  java
  • Linq to sql(四):查询句法(二)

     

    where

    描述:查询顾客的国家、城市和订单数信息,要求国家是法国并且订单数大于5

    查询句法:

    var 多条件 = from c in ctx.Customers

                      where c.Country == "France" && c.Orders.Count > 5

                      select new

                      {

                          国家 = c.Country,

                          城市 = c.City,

                          订单数 = c.Orders.Count

                      };      

    对应SQL:

    SELECT [t0].[Country], [t0].[City], (

        SELECT COUNT(*)

        FROM [dbo].[Orders] AS [t2]

        WHERE [t2].[CustomerID] = [t0].[CustomerID]

        ) AS [value]

    FROM [dbo].[Customers] AS [t0]

    WHERE ([t0].[Country] = @p0) AND (((

        SELECT COUNT(*)

        FROM [dbo].[Orders] AS [t1]

        WHERE [t1].[CustomerID] = [t0].[CustomerID]

        )) > @p1)

    -- @p0: Input String (Size = 6; Prec = 0; Scale = 0) [France]

    -- @p1: Input Int32 (Size = 0; Prec = 0; Scale = 0) [5]    

    orderby

    描述:查询所有没有下属雇员的雇用年和名,按照雇用年倒序,按照名正序

    查询句法:

    var 排序 = from emp in ctx.Employees

                     where emp.Employees.Count == 0

                     orderby emp.HireDate.Value.Year descending, emp.FirstName ascending

                     select new

                     {

                         雇用年 = emp.HireDate.Value.Year,

                         名 = emp.FirstName

                     };     

    对应SQL:

    SELECT DATEPART(Year, [t0].[HireDate]) AS [value], [t0].[FirstName]

    FROM [dbo].[Employees] AS [t0]

    WHERE ((

        SELECT COUNT(*)

      FROM [dbo].[Employees] AS [t1]

        WHERE [t1].[ReportsTo] = [t0].[EmployeeID]

        )) = @p0

    ORDER BY DATEPART(Year, [t0].[HireDate]) DESC, [t0].[FirstName]

    -- @p0: Input Int32 (Size = 0; Prec = 0; Scale = 0) [0]

  • 相关阅读:
    静态页中利用AJAX.NET实现无刷新页面
    先写一个用ajax开发webgis的JS暂停函数问题!
    AJAX.NET用户开发指南
    如何解决“未能在设计视图中打开,在中以不同方式将值括起来
    VB 各种进制相互转换大全
    Ajax学习资源大全
    vb+MAPX开发打开ACESS数据库并于里面的X,Y 数据绑定
    C#区分中英文统计字符串的长度
    DataList小结
    datagrid出现分页符号,却不能切换
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749090.html
Copyright © 2011-2022 走看看