如何在实体框架中控制参数嗅探和/或查询提示? [英] How do I control parameter sniffing and/or query hints in entity framework?

查看:88
本文介绍了如何在实体框架中控制参数嗅探和/或查询提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我已提出一个建议,以在未来版本的EF中实施提示控制。 在这里投票。

Update: I've created a suggestion to implement hint control in a future version of EF. Go here to vote for it.

我有一个实体框架(EF )查询需要花费很长时间才能在Sql Server中执行,尽管当我将生成的TSQL复制并粘贴到Sql Server Management Studio(SSMS)中时,它的运行速度非常快。经过一番调查,我发现我遇到了参数嗅探问题,并且正确的修复方法是插入许多查询提示之一(OPTIMIZE FOR,RECOMPILE等)。如何将这些提示插入我的EF查询中?

I have a problem where one of my Entity Framework (EF) queries is taking a very long time to execute in Sql Server, although when I copy-and-paste the generated TSQL into Sql Server Management Studio (SSMS) it runs extremely fast. After some investigation I found that I was experiencing a parameter sniffing issue, and the correct way to fix it is to insert one of many query hints (OPTIMIZE FOR, RECOMPILE, and so on). How do I insert these hints into my EF queries?

从不同角度来看,与此相关的问题是此处此处此处

Related questions coming at this from different perspectives are here, here, and here.

推荐答案

要将提示应用于由EF生成的查询,您应该在这里使用计划指南,以及更多信息:一对一一个联接在SQL Server中不够快

To apply a hint on a query generate by EF, you should use plan guides, more info here: One to one join Not fast enough in SQL Server

这篇关于如何在实体框架中控制参数嗅探和/或查询提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆