开发者

SQL performance optimization (Entity Framework)

开发者 https://www.devze.com 2023-02-08 10:52 出处:网络
I am experiencing a really poor performance from Entity Framework. I am binding it to views, and querying them takes 3-6x longer using EF.

I am experiencing a really poor performance from Entity Framework.

I am binding it to views, and querying them takes 3-6x longer using EF.

Here is my test case (pseudo), Regular select of the same data:

Select * FROM myView 
WHERE DateField > X 
AND DateField < Y AND ID in ('a','b') 
AND [expirationDateTime] = '9999-12-31'

Execution Time: 0:30

EF generated SQL

exec sp_executesql N'SELECT 
    [Extent1].[Field1] AS [Field1], 
    ...
    FROM  (SELECT 
              [myView].Field1 AS [Field1]
              ...
              FROM [dbo].[myView] AS [myView]) AS [Extent1]
    WHERE ([Extent1].[DateField] > @p_linq__0)
    AND   ([Extent1].DateField] < @p_linq__1)
    AND   ([Extent1].[expirationDateTime] = @p__linq__2)',
    N'@p__linq__0 datetime,@p__linq__1 datetime,@p__linq__2 datetime',
      @p__linq__0='2010-12-01 00:00:00',
      @p__linq__1='2011-01-06 00:00:00',
      @p__linq__2='9999开发者_Python百科-12-31',

Execution Time: 2:54

How can EF query be optimized considering that there is limited control over how the SQL is rendered?


AND ID in ('a','b') seams to be missing from the EF version. That might do a big difference.


did you put WITH (NOLOCK) in all of your views? lol

0

精彩评论

暂无评论...
验证码 换一张
取 消