SQLLINQ LambdaSELECT *FROM HumanResources.Employee from e in Employeesselect e Employees .Select (e = e) SELECT e.LoginID, e.JobTitleFROM HumanResources.Employee AS e from e in Employeessele...
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 ( |
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 ( |
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.* 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 |
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.* 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 |
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三种表达方式转换 转自https://www.cnblogs.com/drzhong/p/4393231.html
- 深入了解TypeScript中的映射类型 2022-10-22
- ajax实现远程通信 2023-01-20
- vue中使用G2问题汇总 2023-10-08
- ajax实现输入提示效果 2023-02-14
- js 中文汉字转Unicode、Unicode转中文汉字、ASCII转换Unicode、Unicode转换ASCII、中文转换X函数代码 2023-08-08
- vue 学习小结(3)关于‘Splan‘ 2023-10-08
- Ajax 配合node js multer 实现文件上传功能 2023-02-14
- JS+CSS实现超漂亮的动态翻书效果(思路详解) 2023-07-09
- 关于javascript:在基于TypeScript的Vue中将vuex状态和 2022-09-16
- JSONP跨域模拟百度搜索 2023-08-12