2

Why does SP called from EF(I'm using version 6.1.3) takes time as compared toSP execution time of SQLCommand's ExecuteNoNQuery() & Datareader? I'm making an Async call using EF like below-

public async Task<IList<T>> ExecSPAsync<T>(string query)
    {
        return await Context.Database.SqlQuery<T>(query).ToListAsync();
    }

Use of SQLCommand/SQLDatareader seems to be much efficient compared with SP call using EF. What would be the efficient way of calling SP using EF?

vinayp
  • 35
  • 4
  • if your stored returns (n)varchar/binary(max), this may be the cause of the issue. See : http://stackoverflow.com/a/28619983/1236044 – jbl Jun 15 '16 at 11:39
  • Thanks. Investigating into places where we are doing this. – vinayp Jun 15 '16 at 14:13

1 Answers1

0

Are you using Code First? Is it the first query in your application? It take some time before EF compiles it's model. Explained in this article including steps to improve the performance.

Václav Holuša
  • 311
  • 3
  • 14
  • Thanks. It does take time for first query, however for now we are concerned with execution of SP using ADO.NET vs EF. – vinayp Jun 15 '16 at 14:13
  • It was just for info so you don't try to seek for an error where it's not. If your concern is about any SP being executed via EF, it will always need some aditional time due to it's complexity. It internally uses ADO.NET and adds some extra stuff for making things easy for developers. Using pure ADO.NET is always quicker but requires more developer work. You need to pick the right one based on your needs. If you need to make stuff as quickiest as possible, then use ADO.NET. It you don't care about tens/hundreds of miliseconds, pick EF as it's easy to use. – Václav Holuša Jun 16 '16 at 07:45