链linq查询的订单执行

编程入门 行业动态 更新时间:2024-10-10 08:18:52
本文介绍了链linq查询的订单执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此代码有区别吗?

var query = DbContext.Customers .Where(<condition>) .Include("Address");

还有

var query = DbContext.Customers .Include("Address") .Where(<condition>);

这是延期查询,我不知道,它是否等效?还是在第二种情况下,在Include之后执行where?

谢谢.

解决方案

对于选择之前的EF顺序而言,没有关系. LINQ查询将转换为SQL查询并运行,并且SQL查询优化器不在乎原始查询的顺序.

正如Patryk所指出的,当以下语句修改查询的结构时,顺序对于Include尤为重要,但是where子句却不能这样做.

在其他LINQ查询中,LINQ-to-Objects的顺序非常重要,因为查询没有按照SQL的方式进行重新优化,并且只是从上到下进行简单处理,并且某些LINQ方法需要以前的方法才能运行完成并处理结果,然后再处理第一个元素(例如OrderBy).

Is there a difference in this code?

var query = DbContext.Customers .Where(<condition>) .Include("Address");

And

var query = DbContext.Customers .Include("Address") .Where(<condition>);

It's deffered query, and I don't know, is it equivalent? Or in the second case where is executed after Include?

Thanks.

解决方案

For EF order prior to the select does not matter. The LINQ query is converted to a SQL query and run and the SQL query optimizer does not care about the order of the original query.

As Patryk pointed out order can matter specifically with Include when the following statements modify the structure of the query, but a where clause doesn't do that.

In other LINQ queries, LINQ-to-Objects, order can matter greatly as the query is not re-optimized the way SQL is and is simply processed from top to bottom, and some LINQ methods require previous methods to run to completion and process results before proceeding to even the first element (OrderBy for example).

更多推荐

链linq查询的订单执行

本文发布于:2023-05-25 19:53:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/236222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:订单   linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!