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

后端 未结 2 1953
天命终不由人
天命终不由人 2021-01-19 05:00

I have an entity defined in an EF 4.0 that is based on a view. The view lays over a table with about 18 million rows of data. I have selected the 4 deterministic properties

2条回答
  •  遥遥无期
    2021-01-19 05:07

    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.

提交回复
热议问题