I have a stored procedure in Azure sql db which when I run from SSMS it completes in about 300 ms.
The sproc takes an id and a date range, collects some data and save it to an aggregation table.
It doesn't return any result.
When it runs from EF code first ExecuteStoreCommand object (with the same parameters)
it takes about 60 seconds to complete.
I have tried to use context.Database.ExecuteSqlCommand and context.Database.SqlQuery
as well with same results, very slow!
Can someone please explain how is it that the EF execution is so slow compare to direct execution of the sproc?
Is there any decent tool out there that can tell me what EF is doing (profiler?)
Without the stored procedure's code it would be hard to tell you which "best practice" you may not be taking into consideration, but this page "Code Project: Performance and the Entity Framework" has a lot of good information about improving EF performance.
This "article" has a lot of good information on using Visual Studio 2010 profiler tools to analyze EF's data access activities.