Order execution of chain linq query
c#, linq, linq-to-entities
Solution
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).
Problem
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.