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 E.nationalidnumber Select E |
Employees . (E = e.nationalidnumber) |
SELECT e.* From HumanResources.Employee as E ORDER by E.hiredate DESC, E.nationalidnumber |
From E in Employees 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 to 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 have e.count (*) > 2 |
From E in Employees Group E by E.jobtitle to 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 Produc TS 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 the 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.product ID = pr. ProductID |
From p in the products Join PR in productreviews on P.productid equals PR. ProductID To 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 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 (Ten) * from production.product as P WHERE p.standardcost < |
(fr Om p in products Where P.standardcost < Select p). Take (Ten) |
Products . Where (P = = (P.standardcost <)) . Take (Ten) |
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 the 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) ) |