为什么"的LINQ to SQL"查询始于FROM关键字不像普通的SQL查询? [英] Why do "linq to sql" queries starts with the FROM keyword unlike regular SQL queries?

查看:133
本文介绍了为什么"的LINQ to SQL"查询始于FROM关键字不像普通的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么LINQ to SQL的查询,以关键字不像普通的SQL查询?

解决方案

LINQ模仿逻辑查询处理在SQL您有:

  8。选择
9. DISTINCT
11. TOP
1.
2.开启
3. JOIN
4.如
5. GROUP BY
6. CUBE / ROLLUP
7. HAVING
10. ORDER BY
12. OFFSET / FETCH
 

但实际上它执行这样的:

  1。从
2.开启
3. JOIN
4.如
5. GROUP BY
6. CUBE / ROLLUP
7. HAVING
8.选择
9. DISTINCT
10. ORDER BY
11. TOP
12. OFFSET / FETCH
 

很多人不知道它,并作出简单的错误,如:

  SELECT山坳AS ALIAS_NAME
从标签
WHERE aliass_name> 10;
 

和问为什么这是行不通的。因为他们假定的顺序是像他们写的。 LINQ 是这件事比较好。

参见逻辑查询处理和<一HREF =htt​​ps://msdn.microsoft.com/en-us/library/ms189499.aspx相对=nofollow> BOL :

  

逻辑处理订单的SELECT语句

     

下列步骤显示的逻辑处理顺序,或结合   订购时,SELECT语句。这个顺序决定了对象时   在一个步骤中定义的提供给在后续的条文   脚步。例如,如果查询处理器可以结合(访问)的   FROM子句中定义的表或视图,这些对象及其   列被提供给所有后​​续步骤。反过来,   因为SELECT子句步骤8,任何列别名或派生   在该条款中定义的列不能由preceding引用   条款。然而,它们可以通过随后的条款,如被引用   ORDER BY子句。需要注意的是的实际物理执行   声明由查询处理器确定,顺序可能有所不同   从这个名单。

  FROM

上

加入

哪里

通过...分组

WITH CUBE和WITH ROLLUP

HAVING

选择

不同

ORDER BY

最佳
 

Why do linq to sql queries starts with the FROM keyword unlike regular SQL queries?

解决方案

LINQ mimics Logical Query processing in 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 executed like:

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 is not aware of it and made simple mistakes like:

SELECT col AS alias_name
FROM tab
WHERE aliass_name > 10;

And ask why it doesn't work. Because they assume that the order is like they write it. LINQ is better at this matter.

See also Logical Query Processing and BOL:

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

这篇关于为什么&QUOT;的LINQ to SQL&QUOT;查询始于FROM关键字不像普通的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆