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 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, &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;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 joins 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 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 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 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) ) |