Entity Framework EF code executing sproc first using ExecuteStoreCommand, very slow

I have a stored procedure in Azure sql db that, when launched from SSMS, finishes in about 300 ms. Sproc accepts an identifier and a date range, collects some data, and stores it in an aggregation table. It does not return any result.

When it is launched from the EF code, first the ExecuteStoreCommand object (with the same parameters) will take about 60 seconds.

I tried using context.Database.ExecuteSqlCommand and context.Database.SqlQuery also with the same results, very slow!

Can someone explain how this is so that the execution of EF is so slow that it compares with the direct execution of sproc?

Is there a decent tool that can tell me what EF does (profiler?)

+4
source share
1 answer

Without stored procedure code, it will be difficult for you to say which "best practice" you cannot take into account, but this page " Code Project: Performance and Entity Framework " contains a lot of good information about improving EF performance.

This article contains a lot of useful information about using Visual Studio 2010 profiler tools to analyze EF data access actions.

0
source

All Articles