• Linq to sql(四):查询句法(一)


    select

    描述:查询顾客的公司名、地址信息

    查询句法:

    var 构建匿名类型1 = from c in ctx.Customers

                          select new

                          {

                              公司名 = c.CompanyName,

                              地址 = c.Address

                          };

    对应SQL

    SELECT [t0].[CompanyName], [t0].[Address]

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

     

    描述:查询职员的姓名和雇用年份

    查询句法:

    var 构建匿名类型2 = from emp in ctx.Employees

                          select new

                          {

                              姓名 = emp.LastName + emp.FirstName,

                             雇用年 = emp.HireDate.Value.Year

                          };

    对应SQL

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

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

     

    描述:查询顾客的ID以及联系信息(职位和联系人)

    查询句法:

    var 构建匿名类型3 = from c in ctx.Customers

                          select new

                          {

                              ID = c.CustomerID,

                              联系信息 = new

                              {

                                  职位 = c.ContactTitle,

                                  联系人 = c.ContactName

                              }

                          };

    对应SQL

    SELECT [t0].[CustomerID], [t0].[ContactTitle], [t0].[ContactName]

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

    描述:查询订单号和订单是否超重的信息

    查询句法:

    var select带条件 = from o in ctx.Orders

                            select new

                            {

                                订单号 = o.OrderID,

                                是否超重 = o.Freight > 100 ? "" : ""

                            };

    对应SQL

    SELECT [t0].[OrderID],

        (CASE

            WHEN [t0].[Freight] > @p0 THEN @p1

            ELSE @p2

         END) AS [value]

    FROM [dbo].[Orders] AS [t0]

    -- @p0: Input Currency (Size = 0; Prec = 19; Scale = 4) [100]

    -- @p1: Input String (Size = 1; Prec = 0; Scale = 0) []

    -- @p2: Input String (Size = 1; Prec = 0; Scale = 0) []

  • 相关阅读:
    学习进度
    移动端使用rem.js,解决rem.js 行内元素占位问题
    利用递归实现数组的扁平化
    ES6 新增声明变量的 var let const 的区别详解
    js学习笔记
    ajax中error函数参数与返回值详解 200 300 400 500
    处理 vue项目 打包后导致css文件引用静态目录路径异常的问题
    vue-cli3 配置 vue.config.js
    使用 vue-cli3 搭建一个项目
    vue-router params 和 query 的区别
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749093.html
Copyright © 2020-2023  润新知