Reputation: 2296
My Entity Framework is set up to emit the SQL generated, followed by the time taken to run the query, to the Output pane.
When I run it locally, the EF query takes .064s (as can be seen in the Output pane), and the SQL (when run by itself in Management Studio) takes about the same. In production the EF query takes .660s, yet the SQL generated only takes .157s.
There are about 50 rows returned. All the other EF queries are running at the expected speed.
What can cause the EF to take so much longer to run than the SQL it generates?
Thank you for any ideas.
Upvotes: 1
Views: 59
Reputation: 119186
The simplest way to figure out why queries run differently when called from different locations is to check the execution plans for both of them. From SSMS it's simply a case of including the plan in the output. For a live SQL Server you can use SQL Profiler.
When you have both plans, compare them and figure out the differences.
One example when a query runs differently is the ARITHABORT
setting. Your app probably connects to SQL Server with this turned off whereas in SSMS it is on. This may cause it to use a different execution plan.
Upvotes: 1