Executing a linq chain query execution

Is there any difference in this code?

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

and

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

He rejected the request and I do not know if it is equivalent? Or in the second case, where is executed after Include ?

Thanks.

+6
source share
1 answer

For ordering EF, it does not matter before selection. The LINQ query is converted to an SQL query and launched, and the SQL query optimizer does not care about the order of the original query.

As Patryk pointed out, the order may matter with Include when the following statements modify the structure of the request, but the where clause does not.

In other LINQ queries, LINQ-to-Objects, order can make a big difference because the query is not over-optimized like SQL and just processed from top to bottom, and some LINQ methods require that the previous methods be executed before completion and the results of the process before proceeding to even the first element (e.g. OrderBy ).

+2
source

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


All Articles