title: How do I control parameter sniffing and/or query hints in entity framework?
body: <p>Update: I've created a suggestion to implement hint control in a future version of EF. <a href="http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/2718461-provide-a-way-to-control-parameter-sniffing-and-or" rel="nofollow noreferrer">Go here to vote for it.</a></p>
  
  <p>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 <a href="http://www.sommarskog.se/query-plan-mysteries.html" rel="nofollow noreferrer">correct way to fix it</a> is to insert one of many query hints (OPTIMIZE FOR, RECOMPILE, and so on). How do I insert these hints into my EF queries?</p>
  
  <p>Related questions coming at this from different perspectives are <a href="https://stackoverflow.com/questions/9270490/entity-framework-4-2-exec-sp-executesql-does-not-use-indexes-parameter-sniffing">here</a>, <a href="https://stackoverflow.com/questions/5158102/force-hint-to-index-from-entity-framework-to-sql-server">here</a>, and <a href="https://stackoverflow.com/questions/2141104/using-nolock-hint-in-ef4">here</a>.</p>