【问题标题】:Entity Framework Performance Inconsistency Compared to Sql Management Studio与 Sql Management Studio 相比,Entity Framework 性能不一致
【发布时间】:2010-05-09 03:52:04
【问题描述】:

我遇到了一个非常基本的 EF 语句超时。我只是从带有 Entity.Title.StartsWith("test") 和 .Take(25) 的单个表中进行选择。当我为没有返回结果的搜索运行此命令时,我得到了超时。

如果我分析并抓取 sql 语句,它看起来很好,如果我在 Management Studio 中运行该 sql,它会在几分之一秒内运行!

为什么相同的查询会在 Management Studio 中运行亚秒级,而当由 EF 生成并从 Asp.Net 应用程序调用时会超时?

【问题讨论】:

    标签: sql-server entity-framework


    【解决方案1】:

    这可能意味着您需要重建统计信息。

    这是由于统计数据过期导致查询计划缓存不正确的常见症状。

    看到这个答案:Why are there performance differences when a SQL function is called from .Net app vs when the same call is made in Management Studio

    这将更新所有统计信息并刷新视图和存储的过程(但要小心在生产机器上运行):

    EXEC sp_updatestats 
    
    EXEC sp_refreshview  
    
    -- Probably won't need this as your are not using stored procs 
    EXEC sp_msForEachTable 'EXEC sp_recompile ''?''' 
    

    【讨论】:

      猜你喜欢
      • 2014-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-27
      相关资源
      最近更新 更多