SQL

LINQ

Lambda

SELECT *FROM HumanResources.Employee

from e in Employees

select e

Employees .Select (e => e)

SELECT e.LoginID, e.JobTitle

FROM HumanResources.Employee AS e

from e in Employees

select new {e.LoginID, e.JobTitle}

Employees.Select (

      e => new {

            LoginID
= e.LoginID, 

            JobTitle
= e.JobTitle

         }

   )

SELECT e.LoginID AS ID, e.JobTitle AS
Title

FROM HumanResources.Employee AS e

from e in Employees

select new {ID = e.LoginID, Title =
e.JobTitle}

Employees.Select (

      e => new 

         {

            ID =
e.LoginID, 

            Title
= e.JobTitle

         }

   )

SELECT DISTINCT e.JobTitle

FROM HumanResources.Employee AS e

(from e in Employees

select e.JobTitle).Distinct()

Employees

   .Select (e => e.JobTitle)

   .Distinct ()

SELECT e.*

FROM HumanResources.Employee AS e

WHERE e.LoginID = 'test'

from e in Employees

where e.LoginID == "test"

select e

Employees

   .Where (e => (e.LoginID == "test"))

SELECT e.*

FROM HumanResources.Employee AS e

WHERE e.LoginID = 'test' AND
e.SalariedFlag = 1

from e in Employees

where e.LoginID == "test"
&& e.SalariedFlag

select e

Employees

   .Where (e => ((e.LoginID == "test") &&
e.SalariedFlag))

SELECT e.* FROM HumanResources.Employee
AS e

WHERE e.VacationHours >= 2 AND
e.VacationHours <= 10

from e in Employees

where e.VacationHours >= 2 &&
e.VacationHours <= 10

select e

Employees

   .Where (e => (((Int32)(e.VacationHours) >= 2) &&
((Int32)(e.VacationHours) <= 10)))

SELECT e.* FROM HumanResources.Employee
AS e

ORDER BY e.NationalIDNumber

from e in Employees

orderby e.NationalIDNumber

select e

Employees

   .OrderBy (e => e.NationalIDNumber)

SELECT e.* FROM HumanResources.Employee
AS e

ORDER BY e.HireDate DESC,
e.NationalIDNumber

from e in Employees

orderby e.HireDate descending,
e.NationalIDNumber

select e

Employees

   .OrderByDescending (e => e.HireDate)

   .ThenBy (e => e.NationalIDNumber)

SELECT e.* FROM HumanResources.Employee
AS e

WHERE e.JobTitle LIKE 'Vice%' OR
SUBSTRING(e.JobTitle, 0, 3) = 'Pro'

from e in Employees

where
e.JobTitle.StartsWith("Vice") || e.JobTitle.Substring(0, 3) ==
"Pro"

select e

Employees

   .Where (e => (e.JobTitle.StartsWith ("Vice") ||
(e.JobTitle.Substring (0, 3) == "Pro")))

SELECT SUM(e.VacationHours)

FROM HumanResources.Employee AS e

Employees.Sum(e => e.VacationHours);

SELECT COUNT(*) FROM
HumanResources.Employee AS e

Employees.Count();

SELECT SUM(e.VacationHours) AS
TotalVacations, e.JobTitle

FROM HumanResources.Employee AS e

GROUP BY e.JobTitle

from e in Employees

group e by e.JobTitle into g

select new {JobTitle = g.Key,
TotalVacations = g.Sum(e => e.VacationHours)}

Employees

   .GroupBy (e => e.JobTitle)

   .Select (

      g => new 

         {

            JobTitle
= g.Key, 

            TotalVacations
= g.Sum (e => (Int32)(e.VacationHours))

         }

   )

SELECT e.JobTitle, SUM(e.VacationHours)
AS TotalVacations

FROM HumanResources.Employee AS e

GROUP BY e.JobTitle

HAVING e.COUNT(*) > 2

from e in Employees

group e by e.JobTitle into g

where g.Count() > 2

select new {JobTitle = g.Key,
TotalVacations = g.Sum(e => e.VacationHours)}

Employees

   .GroupBy (e => e.JobTitle)

   .Where (g => (g.Count () > 2))

   .Select (

      g => 

         new 

         {

            JobTitle
= g.Key, 

            TotalVacations
= g.Sum (e => (Int32)(e.VacationHours))

         }

   )

SELECT *

FROM Production.Product AS p,
Production.ProductReview AS pr

from p in Products

from pr in ProductReviews

select new {p, pr}

Products

   .SelectMany (

      p => ProductReviews, 

      (p, pr) => 

         new 

         {

            p =
p, 

            pr =
pr

         }

   )

SELECT *

FROM Production.Product AS p

INNER JOIN Production.ProductReview AS
pr ON p.ProductID = pr.ProductID

from p in Products

join pr in ProductReviews on p.ProductID
equals pr.ProductID

select new {p, pr}

Products

   .Join (

      ProductReviews, 

      p => p.ProductID, 

      pr => pr.ProductID, 

      (p, pr) => 

         new 

         {

            p =
p, 

            pr =
pr

         }

   )

SELECT *

FROM Production.Product AS p

INNER JOIN Production.ProductCostHistory
AS pch ON p.ProductID = pch.ProductID AND p.SellStartDate = pch.StartDate

from p in Products

join pch in ProductCostHistories on new
{p.ProductID, StartDate = p.SellStartDate} equals new {pch.ProductID,
StartDate = pch.StartDate}

select new {p, pch}

Products

   .Join (

      ProductCostHistories, 

      p => 

         new 

         {

            ProductID
= p.ProductID, 

            StartDate
= p.SellStartDate

         }, 

      pch => 

         new 

         {

            ProductID
= pch.ProductID, 

            StartDate
= pch.StartDate

         }, 

      (p, pch) => 

         new 

         {

            p =
p, 

            pch =
pch

         }

   )

SELECT *

FROM Production.Product AS p

LEFT OUTER JOIN Production.ProductReview
AS pr ON p.ProductID = pr.ProductID

from p in Products

join pr in ProductReviews on p.ProductID
equals pr.ProductID

into prodrev

select new {p, prodrev}

Products

   .GroupJoin (

      ProductReviews, 

      p => p.ProductID, 

      pr => pr.ProductID, 

      (p, prodrev) => 

         new 

         {

            p =
p, 

            prodrev
= prodrev

         }

   )

SELECT p.ProductID AS ID

FROM Production.Product AS p

UNION

SELECT pr.ProductReviewID

FROM Production.ProductReview AS pr

(from p in Products

select new {ID = p.ProductID}).Union(

from pr in ProductReviews

select new {ID = pr.ProductReviewID})

Products

   .Select (

      p => 

         new 

         {

            ID =
p.ProductID

         }

   )

   .Union (

      ProductReviews

         .Select (

            pr
=> 

              
new 

              
{

                  ID
= pr.ProductReviewID

              
}

         )

   )

SELECT TOP (10) *

FROM Production.Product AS p

WHERE p.StandardCost < 100

(from p in Products

where p.StandardCost < 100

select p).Take(10)

Products

   .Where (p => (p.StandardCost < 100))

   .Take (10)

SELECT *

FROM [Production].[Product] AS p

WHERE p.ProductID IN(

SELECT
pr.ProductID

FROM
[Production].[ProductReview] AS [pr]

WHERE
pr.[Rating] = 5

)

from p in Products

where (from pr in ProductReviews

where pr.Rating == 5

select
pr.ProductID).Contains(p.ProductID)

select p

Products

   .Where (

      p => 

         ProductReviews

            .Where
(pr => (pr.Rating == 5))

            .Select
(pr => pr.ProductID)

            .Contains
(p.ProductID)

   )

SQL-LINQ-Lambda语法对照的更多相关文章

  1. SQL,LINQ,Lambda语法对照图(转载)

    如果你熟悉SQL语句,当使用LINQ时,会有似曾相识的感觉.但又略有不同.下面是SQL和LINQ,Lambda语法对照图 SQL LINQ Lambda SELECT * FROM HumanReso ...

  2. SQL,Linq,Lambda之间的转换练习

    1.查询Student表中的所有记录的Sname.Ssex和Class列. SQL:select sname,ssex,class from Students linq:from s in Stude ...

  3. sql linq lambda 对比

    . 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from student Linq: from s in Students ...

  4. SQL-LINQ-Lambda 语法对照

    SQL LINQ Lambda  SELECT *FROM Employees from e in Employees  select e Employees .Select (e => e)  ...

  5. SQL/LINQ/Lamda 写法[转发]

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  6. SQL Linq lamda区别

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  7. SQL/LINQ/Lamda

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  8. SQL-LINQ-Lambda语法对照,好记性不如烂笔头

    忘记的时候就翻阅翻阅吧~~ SQL LINQ Lambda SELECT *FROM HumanResources.Employee from e in Employees select e Empl ...

  9. LINQ之路 4:LINQ方法语法

    书写LINQ查询时又两种语法可供选择:方法语法(Fluent Syntax)和查询语法(Query Expression). LINQ方法语法是非常灵活和重要的,我们在这里将描述使用链接查询运算符的方 ...

随机推荐

  1. Qt中,当QDockWidget的父窗口是一个不可以拖动的QTabWidget的时候实现拖动的方法

    之前在做有关QDockWidget的内容时候遇到了瓶颈,那就是窗口弹出来之后拖动不了,也不可以放大和缩小,若是弹出来之后设置成了window的flags,也不可以拖动,而且也不是需要的效果. 1.弹出 ...

  2. Eclipse开发android安装环境

    好久没有用Eclipse开发android了,今天安装了一下,发现之前的andorid的sdk不能用了,然后去官网下载了一个最新的SDK,由于现在的android的官网需要FQ才能访问到,所以在这里我 ...

  3. javascript 不间断向左滚动图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. TCP/IP笔记 应用层(3)——HTTP

    1. URL URL(Uniform Resource Locator) 相当于一个文件名在网络范围的扩展. 1.1 格式 schema://host[:port#]/path/.../[?query ...

  5. Sql Server2000,2005,2008各版本主要区别

    Emerson回来之后,在过程中遇到的一些问题,再次做一些整理,包括本篇的Sql Server各版本之间的区别和另一篇数据库函数. (博文内容来自网络) 数据类型 SQL Server 2008 数据 ...

  6. Cinder-2 窗口的创建过程

    通过TinderBox生成的代码很简单,整个代码如下: #include "cinder/app/AppNative.h" #include "cinder/gl/gl. ...

  7. webStorm中的混乱代码格式化

    Mac上    command + alt + l windows上 control + alt + l

  8. 李洪强漫谈iOS开发[C语言-033]-三元运算符的应用

  9. linux shell中的特殊符号

    该内容,均来自此网址(http://www.92csz.com/study/linux/12.htm).在下只是把那些命令的截图给去了. 你在学习linux的过程中,也许你已经接触过某个特殊符号,例如 ...

  10. win7 热点设置命令

    netsh wlan set hostednetwork mode=allownetsh wlan set hostednetwork ssid=XXXX key=XXXnetsh wlan star ...