Is Entity Framework Core slower than using ADO .NET and stored procedures

entity-frameworksql server

I'm looking at designing some new software for work, and I have been using EF Core quite a bit in my personal projects.

In my mind, EF Core generates queries for the underlying data provider which returns data. These queries are ad-hoc, or the same as running a query on the MSSQL database through SSMS or equivalent.

I know with stored procedures we get stored execution plans so stored procedure's execute faster next time, as the plan doesn't need to get regenerated again. Therefore, for an enterprise system, EF Core would quite a bit slower for data operations than using, say, something like Dapper and Stored Procedures.

Do I have this completely wrong? Does EF Core on MSSQL somehow cache its execution plans and thus make the performance difference not as huge? Or do I have this entire thing back to front?

Best Answer

I know with Stored Procedures we get stored execution plans so stored procedure's execute faster next time, as the plan doesn't need to get regenerated again.

That's not really true, nowadays. What you said was true 15?-25 years ago, but RDBMSs are pretty sophisticated softwares these days. They can detect when you're sending a query you've already run before and can reuse execution plans. If you think about it, it should be easy to think up how that could be accomplished with paramaterized queries, and so it wouldn't even be a big mental leap to think about how it could be done even with values right in the query.

So, nowadays, stored procedures have virtually no benefit with regards to performance over regular SQL queries. They can still be useful for certain situations, where queries have convoluted permissions associated with them, and a few other uncommon situations.

Most of the old benefits of SPs you can get now with just straight SQL, which EF supports handwriting queries for cases where you need it.