Comparing Entity Framework Vs Dapper
2 min read
This has been a thing in the past that I've discussed with collegues and it's still coming up today so I thought I'd leave my thoughts about it here. Which one of these should you choose to move forward with whatever you're developing?
Dapper isn't a framework
It isn't an ORM either for that matter. Some people call it a micro-ORM, I think because it came from the movement to move away from large cumbersome frameworks like NHibernate. In my head though it is simply a way to call a statement that would otherwise run on a database, have it execute, and have that information mapped to a class. That's it. Nothing ORM about it. You can definitely add that functionality if you'd like, but that would be an extension to what the core dapper project was created for.
EF does magic
EF has its uses for sure. It has a lot of cool things it does. How it does them though isn't always clear. If you have something that is unexpected than you have to take the time to figure out why it is doing what it is doing and that might be cumbersome. That's how it should be though, it's a Framework, you are playing by it's rules but hopefully getting some benefits of being within those constraints.
Dapper is an extension
To me I look at Dapper as what the original ADO.NET should have been. That brings me to my main argument, if Dapper was a part of Mircrosoft's System.Data namespace would you even be having this conversation? Most likely not. You would use EF for it's strengths and when you needed more "control" you'd use System.Data.Dapper. Therein lies my conclusion.
The entry barrier to dapper is super low. Either you know SQL or you don't. If you have no idea what SQL is then just stick to EF. If you want more control use Dapper. If you want to integrate things like GraphQL and OData then use EF. If you are having performance issues and really need to shave the time of the query use Dapper. Say you encounter code that uses either EF or Dapper and don't understand what you are looking at. Use the method that you think is the easiest way to accomplish the task and move on with life.