Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 23, 2026·3 min de lecture

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.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Dapper Overview
Commande CLI universelle
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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires