title: Performance of stored procedures & Entity Framework
body: <p>Are there any obvious reasons why calling a stored procedure via my entity model would result in far slower performance than calling it direcly?</p>
  
  <p>Firstly, I don't expect the SP to run at <em>exactly</em> the same speed and I know that there are various things that EF has to do that wouldn't be called when accessing the SP directly.</p>
  
  <p>That aside, I have a query that returns three columns of strings. It runs pretty much instantly when I execute it via Enterprise Manager. If I run it via EF then it takes about six seconds. Granted, the results are being mapped into a complex type but when I've ran the query through SQL Server Profiler it's clear to see that the delay happens on the SQL server:</p>
  
  <p><img src="https://i.stack.imgur.com/Ls24D.jpg" alt="Performance of query being executed from two sources in SQL Server Profiler"></p>
  
  <p>On the diagram, 1 indicates the SQL being called from Enterprise Manager, 2 indicates it being called via my app using EF.</p>
  
  <p>Is there anything obvious I'm doing wrong here? I'd expect a delay of maybe a second or two, but the difference seems too great.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It seems that the stored procedure also runs slowly when called via ADO.Net. My colleague seems to think it's something to do with a bad execution plan that .Net is caching. By editing the stored procedure and saving it again it seemed to clear whatever was in the cache and both the ADO.Net and EF call to the stored procedure work well. </p>
  
  <p>Has anyone else encountered anything like this before?</p>