我们有一个类似于以下内容的查询:
from x in db.Table.Include(x => x.Parent) .Include(x => x.Parent.Relation) .Include(x => x.Relation) .Include(x => x.Children) where /* some query */ select x
问题在于,在添加时.Include(x => x.Children),ORDER BY实体框架添加到生成的SQL的语句会使查询花费很长时间才能执行- 类似于以下内容:
.Include(x => x.Children)
ORDER BY
ORDER BY [Project2].[Id1] ASC, [Project2].[Id2] ASC, [Project2].[Id] ASC, [Project2].[C4] ASC
向linq查询中添加orderby也无济于事,除了添加其他列作为排序依据之外,它不会影响上面的语句。
显然,这是EF在内部做的事情,以简化事后创建对象的过程。您无法删除order by说明。
order by