We have a query similar to the following:
from x in db.Table.Include(x => x.Parent) .Include(x => x.Parent.Relation) .Include(x => x.Relation) .Include(x => x.Children) where select x
The problem is that when you add .Include(x => x.Children) the ORDER BY , which the Entity Framework adds to the generated SQL, causes the query to execute a lot of time - something like below:
ORDER BY [Project2].[Id1] ASC, [Project2].[Id2] ASC, [Project2].[Id] ASC, [Project2].[C4] ASC
Adding orderby to the linq query also does not help, it does not affect the above statement, except for adding an additional column for sorting.
Jamie source share