Internative Logo

What Is Dapper? The Micro-ORM for Fast SQL in .NET

What Is Dapper? The Micro-ORM for Fast SQL in .NET

Every .NET application that talks to a relational database has to turn rows into objects. Writing that by hand with ADO.NET means opening readers, checking for nulls and copying column after column into properties. A full ORM removes that work but also writes the SQL for you, which is not always what you want on a hot path. Dapper sits between the two: you write the SQL, and Dapper turns the result into typed C# objects with almost no overhead.

This article explains what Dapper is, how it works, where it shines, where a full ORM is the better choice, and how it compares with Entity Framework Core and plain ADO.NET.

What is Dapper?

Dapper is an open-source micro-ORM for .NET. It is a small library of extension methods on the standard IDbConnection interface that runs a SQL query and maps each row to an object, and it works with any ADO.NET provider: SQL Server, PostgreSQL, MySQL, SQLite, Oracle and others.

Dapper was built at Stack Overflow by Sam Saffron and Marc Gravell. In a blog post on 30 March 2011, Saffron described why: Stack Overflow had started on LINQ to SQL, and the web tier was often running at 100% CPU, largely because of the cost of the ORM on very simple, frequent queries. The team replaced the hot paths with hand-written SQL and a tiny, fast mapper, and released it as open source on Google Code in spring 2011 under the Apache 2.0 licence. The project is developed on GitHub in the DapperLib organisation and ships on NuGet as the Dapper package.

"Micro" is the important word. Dapper does not track changes, generate SQL, manage relationships or create database schemas. It does one job, mapping, and does it quickly.

How Dapper works

Extension methods on a connection. You open a normal database connection and call methods such as Query<T>, QueryFirstOrDefault<T>, Execute or their async versions. There is no context object, no model configuration and no start-up cost.

Parameters, not string concatenation. Values are passed as an anonymous object, for example new { CustomerId = id }. Dapper turns them into proper database parameters, which protects against SQL injection and lets the database reuse query plans. A list passed as a parameter is expanded for IN clauses.

Fast, cached mapping. The first time a query runs, Dapper generates and caches the code that maps columns to properties for that query and type. Every later call reuses it, which is why its overhead over a hand-written DataReader loop is small.

Multi-mapping and multiple results. A single query that joins orders and customers can be split into an Order with its Customer attached. QueryMultiple reads several result sets from one round trip, which is useful for a page that needs a header, its lines and some totals.

Your transactions, your SQL. Dapper uses whatever transaction you pass in, and can call stored procedures as easily as inline SQL.

Key features

  • Near raw ADO.NET speed for reads, with very low memory allocation.
  • Works with any ADO.NET provider, so the same code style covers Microsoft SQL Server, PostgreSQL, MySQL and SQLite.
  • Full control of SQL: window functions, CTEs, hints and vendor-specific features are just SQL.
  • Parameterised queries by default, including list expansion.
  • Multi-mapping of joined results into object graphs.
  • Async API for every operation.
  • A tiny dependency: one package, no configuration, easy to add to an existing codebase.

Where Dapper is used

  • High-traffic read paths: product listings, feeds, search results and dashboards where every millisecond counts.
  • Reporting and analytics queries that are easier to write and tune in SQL than to express through an ORM.
  • Existing databases with stored procedures and schemas that were not designed around an ORM.
  • Microservices with a small data layer, where a full ORM would add more weight than value.
  • Next to EF Core in the same application: EF Core for writes and domain logic, Dapper for the heavy queries.

When to choose Dapper, and when not to

Choose Dapper when:

  • Query performance and predictable SQL matter more than development speed for that part of the system.
  • Your team is comfortable writing and reviewing SQL.
  • You work with a database you do not control, or one full of stored procedures and views.
  • You want a thin, transparent data layer where nothing happens that you did not write.

Look elsewhere when:

  • The domain has many related entities that are created, updated and saved together. Entity Framework Core handles change tracking, relationships and the unit of work for you.
  • You want schema migrations generated from your model. Dapper has none; you would add a tool such as DbUp or FluentMigrator.
  • Most of the work is simple CRUD. Writing every INSERT and UPDATE by hand is slow and error-prone, even with helper packages such as Dapper.Contrib.
  • The team is not strong in SQL. Dapper does not hide the database, so poor queries stay poor.

Dapper and its alternatives

OptionTypeSQL written byBest fit
DapperMicro-ORMYouHot read paths, reporting, existing schemas
Entity Framework CoreFull ORMEF Core (LINQ), raw SQL possibleDomain-rich apps, CRUD, migrations
ADO.NETLow-level APIYou, plus manual mappingMaximum control, special cases
linq2dbLightweight LINQ ORMlinq2db (LINQ)Typed queries without change tracking
RepoDBHybrid ORMMostly the libraryFast CRUD helpers with raw SQL fallback

The real decision for most teams is Dapper vs EF Core, and it is rarely either-or. EF Core gives productivity, migrations and a model of your domain; Dapper gives control and speed on the queries that need it. Recent EF Core versions have narrowed the performance gap for simple no-tracking queries, so the stronger argument for Dapper is usually control over the SQL rather than raw speed. Both run on modern .NET, and they can share the same connection and transaction.

How we use Dapper at Internative

We use Dapper in performance-critical backend services where fine-grained control over SQL and efficiency matter. It lets us build fast, predictable data layers while keeping the infrastructure simple and transparent: the query that runs in production is the query we wrote and reviewed.

If you are building a backend where data access speed matters, or tuning one that has slowed down, our enterprise software team can help you decide where Dapper fits next to your ORM.

Frequently asked questions

Is Dapper an ORM?

Yes, a micro-ORM. It maps query results to objects, which is the "mapping" part of an ORM, but it does not generate SQL, track changes or manage relationships. Those are the features that make a full ORM such as EF Core.

Should I use EF Core or Dapper?

Use EF Core as the default for applications with a rich domain model, lots of CRUD and schema migrations. Use Dapper for read-heavy or performance-critical queries, reporting and databases built around stored procedures. Many .NET applications use both: EF Core for writes, Dapper for the heavy reads.

Is Dapper faster than EF Core?

Usually, yes, especially for read queries, because it does no change tracking and no LINQ translation. The gap has narrowed in recent EF Core versions for no-tracking queries. In practice a well-written query and the right indexes matter more than the choice of library.

Is Dapper free?

Yes. Dapper is open source under the Apache 2.0 licence and can be used in commercial applications at no cost.

What is Dapper in .NET Core?

The same library. Dapper targets .NET Standard and modern .NET, so it runs in .NET Core and current .NET applications, including ASP.NET Core APIs, as well as in older .NET Framework projects.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.