Why do "linq to sql" queries start with the FROM keyword, unlike regular SQL queries?

Why do linq sql queries start with a keyword FROMas opposed to regular SQL queries?

+2
source share
2 answers

LINQ mimics Logical Query processingin SQL you have:

8. SELECT
9. DISTINCT
11. TOP
1. FROM
2. ON
3. JOIN
4. WHERE
5. GROUP BY
6. WITH CUBE/ROLLUP
7. HAVING
10. ORDER BY
12. OFFSET/FETCH

But actually it is executed as:

1. FROM
2. ON
3. JOIN
4. WHERE
5. GROUP BY
6. WITH CUBE/ROLLUP
7. HAVING
8. SELECT
9. DISTINCT
10. ORDER BY
11. TOP
12. OFFSET/FETCH

Many people are not aware of this and make simple mistakes, for example:

SELECT col AS alias_name
FROM tab
WHERE aliass_name > 10;

And ask why this is not working. Because they suggest that the order is similar to what they write. LINQbetter on this.

See also Logical Query Processing and BOL :

SELECT

, SELECT. , , . , () , FROM, . , SELECT 8, , , . , ORDER BY. , , .

FROM

ON

JOIN

WHERE

GROUP BY

WITH CUBE or WITH ROLLUP

HAVING

SELECT

DISTINCT

ORDER BY

TOP
+5

, , , , It is more similar to "foreach". this , LINQ LINQ.

LINQ. .

  • LINQ (Linq to Objects)
  • DLINQ (Linq to SQL)
  • XLINQ (Linq to XML)
0

Source: https://habr.com/ru/post/1608414/


All Articles