sql-serverentity-frameworkquery-hintsparameter-sniffing

How do I control parameter sniffing and/or query hints in entity framework?


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?


Solution

  • 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