gpt4 book ai didi

c# - 与常规 SQL 查询不同,为什么 "linq to sql"查询以 FROM 关键字开头?

转载 作者:行者123 更新时间:2023-12-02 11:01:40 25 4
gpt4 key购买 nike

与常规 SQL 查询不同,为什么 linq to sql 查询以 FROM 关键字开头?

最佳答案

LINQ 模仿 SQL 中的逻辑查询处理:

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

但实际上它的执行方式是这样的:

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

许多人没有意识到这一点并犯了一些简单的错误,例如:

SELECT col AS alias_name
FROM tab
WHERE aliass_name > 10;

并询问为什么它不起作用。因为他们认为订单就像他们写的那样。 LINQ 在这方面做得更好。

另请参阅Logical Query ProcessingBOL :

Logical Processing Order of the SELECT statement

The following steps show the logical processing order, or binding order, for a SELECT statement. This order determines when the objects defined in one step are made available to the clauses in subsequent steps. For example, if the query processor can bind to (access) the tables or views defined in the FROM clause, these objects and their columns are made available to all subsequent steps. Conversely, because the SELECT clause is step 8, any column aliases or derived columns defined in that clause cannot be referenced by preceding clauses. However, they can be referenced by subsequent clauses such as the ORDER BY clause. Note that the actual physical execution of the statement is determined by the query processor and the order may vary from this list.

FROM

ON

JOIN

WHERE

GROUP BY

WITH CUBE or WITH ROLLUP

HAVING

SELECT

DISTINCT

ORDER BY

TOP

关于c# - 与常规 SQL 查询不同,为什么 "linq to sql"查询以 FROM 关键字开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32668427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com