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 FROM HumanResources.Employee AS e |
from e in Employees select new {ID = e.LoginID, Title = |
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 |
from e in Employees where e.LoginID == "test" select e |
Employees |
SELECT e.* FROM HumanResources.Employee WHERE e.VacationHours >= 2 AND |
from e in Employees where e.VacationHours >= 2 && select e |
Employees |
SELECT e.* FROM HumanResources.Employee |
from e in Employees orderby e.NationalIDNumber select e |
Employees |
SELECT e.* FROM HumanResources.Employee ORDER BY e.HireDate DESC, |
from e in Employees orderby e.HireDate descending, select e |
Employees |
SELECT e.* FROM HumanResources.Employee WHERE e.JobTitle LIKE 'Vice%' OR |
from e in Employees where select e |
Employees |
SELECT SUM(e.VacationHours) FROM HumanResources.Employee AS e |
Employees.Sum(e => e.VacationHours); |
|
SELECT COUNT(*) FROM |
Employees.Count(); |
|
SELECT SUM(e.VacationHours) AS 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, |
Employees |
SELECT e.JobTitle, SUM(e.VacationHours) 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, |
Employees |
SELECT * FROM Production.Product AS p, |
from p in Products from pr in ProductReviews select new {p, pr} |
Products |
SELECT * FROM Production.Product AS p INNER JOIN Production.ProductReview AS |
from p in Products join pr in ProductReviews on p.ProductID select new {p, pr} |
Products |
SELECT * FROM Production.Product AS p INNER JOIN Production.ProductCostHistory |
from p in Products join pch in ProductCostHistories on new select new {p, pch} |
Products |
SELECT * FROM Production.Product AS p LEFT OUTER JOIN Production.ProductReview |
from p in Products join pr in ProductReviews on p.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 FROM WHERE ) |
from p in Products where (from pr in ProductReviews where pr.Rating == 5 select select p |
Products |