Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsMay 23, 2026·3 min de lectura

Dapper — High-Performance Micro ORM for .NET

A lightweight object mapper for .NET that extends IDbConnection with fast methods for querying and executing SQL against any database.

Listo para agents

Este activo puede ser leído e instalado directamente por agents

TokRepo expone un comando CLI universal, contrato de instalación, metadata JSON, plan según adaptador y contenido raw para que los agents evalúen compatibilidad, riesgo y próximos pasos.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Dapper Overview
Comando CLI universal
npx tokrepo install 26337977-56c4-11f1-9bc6-00163e2b0d79

Introduction

Dapper is a lightweight object mapper for .NET created by the Stack Overflow engineering team. It extends IDbConnection with convenience methods that map query results directly to strongly typed objects while delivering near-raw ADO.NET performance.

What Dapper Does

  • Maps SQL query results to C# objects with minimal overhead
  • Supports parameterized queries to prevent SQL injection
  • Handles multi-mapping for complex joins across multiple tables
  • Provides async variants of all query and execute methods
  • Works with any database that has an ADO.NET provider

Architecture Overview

Dapper operates as a set of extension methods on IDbConnection. It uses IL emission and caching to generate optimized mapping functions at runtime, avoiding the reflection overhead typical of full ORMs. There is no change tracking, no identity map, and no query generation. You write the SQL, Dapper maps the results.

Self-Hosting & Configuration

  • Install via NuGet: dotnet add package Dapper
  • No configuration files or startup registration required
  • Works with SqlConnection, NpgsqlConnection, MySqlConnection, and any IDbConnection
  • Add Dapper.Contrib for CRUD helpers or Dapper.SqlBuilder for dynamic queries
  • Compatible with .NET Framework 4.6.1+ and .NET 6 through .NET 9

Key Features

  • Near-raw ADO.NET speed with object mapping convenience
  • Multi-mapping to split a single row into multiple objects
  • Stored procedure support with output parameters
  • Buffered and unbuffered result streaming
  • Transaction support through standard IDbTransaction

Comparison with Similar Tools

  • Entity Framework Core — full ORM with change tracking and migrations; heavier overhead, more abstraction
  • ADO.NET (raw) — no mapping layer; fastest but verbose and error-prone
  • RepoDB — hybrid ORM with micro and full ORM features; smaller community
  • ServiceStack.OrmLite — convention-based mapping; commercial license required
  • PetaPoco — similar micro ORM approach; less active maintenance

FAQ

Q: When should I choose Dapper over Entity Framework Core? A: Use Dapper when you need maximum query performance, prefer writing your own SQL, or work with existing stored procedures. EF Core suits projects that benefit from migrations, change tracking, and LINQ query building.

Q: Does Dapper support database migrations? A: No. Dapper is purely a query mapper. Use a dedicated migration tool like FluentMigrator or EF Core migrations alongside it.

Q: Can Dapper map one-to-many relationships? A: Yes, using multi-mapping and QueryMultiple APIs. You split joined rows into parent and child objects, then assemble them in application code.

Q: Is Dapper safe from SQL injection? A: Yes, as long as you use parameterized queries. Dapper passes parameters to the underlying ADO.NET provider, which handles safe escaping.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.