Dapper VS Entity Framework

Vinícius Miranda Baptista
3 min readMay 24, 2022

--

Image Ref: https://chaitanyasuvarna.wordpress.com/2021/06/28/using-dapper-over-entityframework/

In the first place, do you know what a ORM(Entity) and a Micro ORM(Dapper) is?

Well, simply put, the Object Relational Mapper is a technique to approach the Object Oriented Programming to the Relational Database paradigm. It is
performed through an Object Relational Mapper, which is usually a library or a Framework.

The Micro Object Relational Mapper basically does database query’s and creates objects based on them. This type of ORM saves your coding time and is lighter than a full ORM.

What is Entity Framework and Dapper?

Entity(Microsoft docs):

Entity Framework (EF) Core is a lightweight, extensible, open source and cross-platform version of the popular Entity Framework data access technology.

EF Core can serve as an object-relational mapper (O/RM), which:

- Enables .NET developers to work with a database using .NET objects.

- Eliminates the need for most of the data-access code that typically needs to be written.

EF Core supports many database engines, see Database Providers for details.

Dapper(Wikipedia):

Dapper is an object–relational mapping (ORM) product for the Microsoft .NET platform: it provides a framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant portion of relational data persistence-related programming tasks. Dapper is free as open source software that is distributed under dual license, either the Apache License 2.0 or the MIT License.

Advantages and disadvantages:

Image Ref: https://leakpack.com/advantages-disadvantages-mechanical-seals/

Entity F. Advantages:

  • Reduces the development cost and time;
  • Generate a new DB, with coding or using boxes and lines whit the EF Designer;
  • Provides auto-generated code;
  • LINQ (One common syntax).

Entity F. disadvantages:

  • It is not available for every database;
  • We cannot control the query’s generated by the provider;
  • Sometimes the query result takes a while due to the robustness of the code.

Dapper Advantages:

  • You write the query exactly as in the DB;
  • In this micro ORM is simple to turn the result of the query in objects;
  • There is no doubt that it is the fastest in reading query’s;
  • Easily to excute query’s.

Dapper disadvantages:

  • Cannot generate auto query’s;
  • Cannot see the changes and track an object.
  • No class model generation

Conclusion:

Both are good options to manage your .NET project, and can be used together to get better results on the code. For reading query’s, in the most of cases, Dapper will be performing better! For INSERT, UPDATE and DELETE query, EF Core will be a good choice, especially if you want to do validations, see what is being modified and create more structed objects.

You always have to analyze the time of development and the application scale to decide what ORM to use. In small applications I preffer to use only EF Core, and in large scale applications I like most to use both :)

Sincerely, Vinícius, have a good day!

--

--

Vinícius Miranda Baptista
Vinícius Miranda Baptista

Written by Vinícius Miranda Baptista

Full Stack Developer 📘 React | Python | C# 🚀 Microsoft DevOps Engineer Expert 🏅 4x Microsoft Certified | FIAP | SENAI