What's the difference between Dapper and EF Core FromSql / ExecuteSQL?

c# dapper entity-framework-core

Question

What is the difference between EF Core FromSql / ExecuteSQL and Dapper? They are both using raw SQL commands. Is the only difference being, Dapper is faster and has higher performance than the latest Entity Framework Core?

1
0
10/7/2018 8:08:25 PM

Popular Answer

If you're using EF to issue SQL requests, you're not really using EF. The calls are line for line equivalent to ADO, and the loading of the result object, which you get to define and maintain, is trivial. Lots of folk use EF, but then use Dapper for the times they want to do raw SQL. Dapper caches the mapping of the result-set to POCO, so subsequent queries run faster. I don't think EF does this. Also the parameter handling is much nicer in Dapper.

But you're still stuck with SQL in string literals, every error is a runtime error and you have to write and maintain your result POCOs. I contend you'll be happier and live longer if you use QueryFirst (disclaimer: which I wrote). Your SQL in a .sql file, syntax validated as you type. Your POCOs generated at design time from your query results. Your queries continually integration tested, and numerous other benefits which I'll be documenting shortly!

2
1/24/2017 10:17:44 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow