# 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. ## Install Save as a script file and run: # Dapper — High-Performance Micro ORM for .NET ## Quick Use ```bash dotnet add package Dapper ``` ```csharp using var conn = new SqlConnection(connStr); var users = conn.Query("SELECT * FROM Users WHERE Age > @Age", new { Age = 25 }); ``` ## 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 - https://github.com/DapperLib/Dapper - https://www.learndapper.com/ --- Source: https://tokrepo.com/en/workflows/asset-26337977 Author: Script Depot