How can I keep Entity Framework from generating inefficient queries in SQL Server?

≡放荡痞女 提交于 2019-12-01 17:47:12
jerry

If there is consistency in the names and order of the columns in the 'order by' clause, there is likely desirability for this result by the users.

Just put an index on the table, or modify the primary key, so that index can be used in the retrieval.

create index x on [dbo].[ftCostBenchmark]
                      ([MonthBeginDt],
                       [dmCostBenchmarkKey],
                       [dmProductKey],
                       [IsImputedFlg])
                  include
                       (existing-primarykey-on-the-table)

Odd that there is no where clause on the query. If you trimmed a where-clause for brevity, put those fields first in the index.

Row limits don't make any sense without specifying an order.

If you want to retrieve records in storage order, create a clustered index and explicitly specify it in your query.

One way to do this is with a query interceptor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!