Mapster maps and projects between .NET types with low allocation overhead. It supports Adapt helpers, EF query projections, dependency injection, and optional Roslyn code generation.
Overview
Mapster is a .NET library for mapping DTOs and domain models without hand-written property copies. Adapt extensions create new instances or populate existing objects, and ProjectToType builds IQueryable projections for Entity Framework queries.
Registration through AddMapster supplies an IMapper via dependency injection, which helps teams migrate from other mappers with similar patterns. Mapster.Tool can emit DTO types and mapper classes at build time for compile-time validation and faster runtime paths.
Published benchmarks compare Mapster with AutoMapper, Mapperly, and Facet for flat DTO scenarios, highlighting its focus on speed and memory use. Optional packages cover EF Core, JSON.NET, immutable collections, and diagnostics.
NuGet packages and the dotnet tool ship stable and prerelease channels documented on the project site.
Key features
- Adapt mapping to new or existing objects
- IQueryable ProjectToType projections
- Dependency-injection IMapper registration
- Mapster.Tool code generation for DTOs
- Optional EF Core and JSON.NET packages
- Benchmarked against other .NET mappers
Use cases
- Map objects to response DTOs
- Project database queries directly to view models
- Generate compile-time mappers for large models