Dapper still lets you run hand-written SQL from C# with almost no overhead. This guide goes from basic queries and multi-mapping to transactions, genuine bulk inserts and Dapper.AOT for Native AOT, and says when EF Core remains the better fit.
Key points
- QueryAsync and Execute extend any DbConnection; version 2.1.89 (September 2026) targets .NET Framework 4.6.1 through .NET 10.
- Register an IDbConnectionFactory instead of one shared connection, since ADO.NET connections are not thread-safe and pooling keeps per-call creation cheap.
- QuerySingleOrDefault suits primary-key lookups: a second row becomes an exception rather than a silently picked first match.
- WHERE Id IN @ids expands a collection into separate parameters; SQL Server allows at most 2,100 parameters per command.
- QueryMultipleAsync returns several result sets in one round trip, and CommandDefinition carries a CancellationToken and commandTimeout.
- Passing a list to Execute runs one INSERT per item; a TVP, SqlBulkCopy, OPENJSON or Dapper Plus is the real bulk path.
Why it matters
Choosing Dapper is less about replacing an ORM than about where you want to spend effort: you keep full control of the SQL and the mapping code stays explicit, but migrations, change tracking and query generation become your problem again. Teams moving an existing EF Core data layer usually find the cost sits in queries and migrations, not in the models.
The same package version serves .NET Framework 4.6.1 era services and .NET 10 ones, so a single data access layer can span old and new projects. If Native AOT is on the roadmap, plan Dapper.AOT from the start rather than retrofitting it, and treat bulk loading as a separate decision with its own mechanism.
Real-world use
- An ASP.NET Core minimal API endpoint that returns a customer together with its orders and review count in one round trip.
- A stock import job loading thousands of rows, where handing a list to Execute would cost one round trip per item.
- A report export that streams tens of thousands of orders to CSV rather than buffering them all in memory.
- A search screen with optional filters, built with a StringBuilder and DynamicParameters so no value enters the SQL text.
This summary was generated by the agent from the original post on C# Corner. The full text and all rights belong to its author and publisher. Go to original