SQL,LINQ,Lambda语法对照图(转载)
如果你熟悉SQL语句,当使用LINQ时,会有似曾相识的感觉.但又略有不同.下面是SQL和LINQ,Lambda语法对照图
|
SQL |
LINQ | Lambda |
|---|---|---|
|
SELECT * FROM HumanResources.Employee |
from e in Employees select e |
Employees |
|
SELECT e.LoginID, e.JobTitle FROM HumanResources.Employee AS e |
from e in Employees select new {e.LoginID, e.JobTitle} |
Employees |
|
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 DISTINCT e.JobTitle FROM HumanResources.Employee AS e |
(from e in Employees select e.JobTitle).Distinct() |
Employees |
|
SELECT e.* FROM HumanResources.Employee AS e WHERE e.LoginID = 'test' |
from e in Employees where e.LoginID == "test" select e |
Employees |
|
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 |
|
SELECT e.* WHERE e.VacationHours >= 2 AND e.VacationHours <= 10 |
from e in Employees where e.VacationHours >= 2 && e.VacationHours <= 10 select e |
Employees |
|
SELECT e.* FROM HumanResources.Employee AS e |
from e in Employees orderby e.NationalIDNumber select e |
Employees |
|
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 |
|
SELECT 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 |
|
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 |
|
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 |
|
SELECT * FROM Production.Product AS p, Production.ProductReview AS pr |
from p in Products from pr in ProductReviews select new {p, pr} |
Products |
|
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 |
|
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 |
|
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 |
|
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 TOP (10) * FROM Production.Product AS p WHERE p.StandardCost < 100 |
(from p in Products where p.StandardCost < 100 select p).Take(10) |
Products |
|
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 |
SQL,LINQ,Lambda语法对照图(转载)的更多相关文章
- SQL,Linq,Lambda之间的转换练习
1.查询Student表中的所有记录的Sname.Ssex和Class列. SQL:select sname,ssex,class from Students linq:from s in Stude ...
- sql linq lambda 对比
. 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from student Linq: from s in Students ...
- SQL-LINQ-Lambda 语法对照
SQL LINQ Lambda SELECT *FROM Employees from e in Employees select e Employees .Select (e => e) ...
- SQL/LINQ/Lamda 写法[转发]
SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees .Sele ...
- SQL Linq lamda区别
SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees .Sele ...
- SQL/LINQ/Lamda
SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees .Sele ...
- SQL-LINQ-Lambda语法对照,好记性不如烂笔头
忘记的时候就翻阅翻阅吧~~ SQL LINQ Lambda SELECT *FROM HumanResources.Employee from e in Employees select e Empl ...
- SQL-LINQ-Lambda语法对照
SQL LINQ Lambda SELECT *FROM HumanResources.Employee from e in Employees select e Employees .Select ...
- 对于SQL的Join,在学习起来可能是比较乱的。我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚。Coding Horror上有一篇文章,通过文氏图 Venn diagrams 解释了SQL的Join。我觉得清楚易懂,转过来。
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codi ...
随机推荐
- Js图片切换
<!DOCTYPE html><html<head> <meta charset="UTF-8"> <title></t ...
- super一些要点
package o6; class Grandparent { public Grandparent() { System.out.println("GrandParent Created. ...
- hdu1160 LIS变形
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 题意:两个子序列 一个是升序,一个是降序,求最长的子序列是多长,并输出路径.(答案不 ...
- 配置.net连接数据库的配置文件
今天调试一个学生信息管理系统时,启动系统之后,登录时老是报错说实例有问题,拿着报错信息去找方法也没遇到能解决问题的,最后怀疑是数据库配置和配置文件不匹配, 发现自己的数据库里并没有SQLEXPRESS ...
- poj 2774 Long Long Message 后缀数组基础题
Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 24756 Accepted: 10130 Case Time Limi ...
- HttpHandler与HttpModule的用处与区别
问题1:什么是HttpHandler? 问题2:什么是HttpModule? 问题3:什么时候应该使用HttpHandler什么时候使用HttpModule? 答案1:HttpHandler,Http ...
- java中的URLConnection和HttpURLConnection
URL url = new URL(strUrl); URLConnection con = url.openConnection(); URL url = new URL(strUrl); Http ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams
A. Anagrams time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- BZOJ4380 : [POI2015]Myjnie
将$c$离散化,设: $f[i][j][k]$为区间$[i,j]$最小值为$k$的最大收益. $g[i][j][k]$为$\max(g[i][j][k..m])$. $h[i][j]$为对于当前DP区 ...
- spring aop两种配置方式(1)
第一种:注解配置AOP注解配置AOP(使用 AspectJ 类库实现的),大致分为三步: 1. 使用注解@Aspect来定义一个切面,在切面中定义切入点(@Pointcut),通知类型(@Before ...