Mapster - The Mapper of Your Domain

May 18, 2026 · View on GitHub

Mapster Icon

Mapster - The Mapper of Your Domain

Writing mapping methods is a machine job. Do not waste your time, let Mapster do it.

NuGet Sources

NuGet Packages

PackageStablePre-release
MapsterMapsterMapster
Mapster.CoreMapster.CoreMapster.Core
Mapster.DependencyInjectionMapster.DependencyInjectionMapster.DependencyInjection
Mapster.EFCoreMapster.EFCoreMapster.EFCore
Mapster.EF6Mapster.EF6Mapster.EF6
Mapster.JsonNetMapster.JsonNetMapster.JsonNet
Mapster.ImmutableMapster.ImmutableMapster.Immutable
Mapster.DiagnosticsMapster.Diagnostics
ExpressionDebuggerExpressionDebugger

DotNet Tools

ToolStablePre-release
Mapster.ToolMapster.ToolMapster.Tool

Installation

Install Mapster with the NuGet CLI:

Install-Package Mapster

Or use the .NET core CLI to install Mapster:

dotnet add package Mapster --project <PROJECT_NAME>

Basic usage

Mapping to a new object

Mapster creates the destination object and maps values to it.

var destObject = sourceObject.Adapt<Destination>();

Mapping to an existing object

You create the object, Mapster maps to the object.

sourceObject.Adapt(destObject);

Use Mapster with Dependency Injection

You can get your IMapper instance via dependency injection, so you do not have to change code, when migrating to mapster from automapper!

Just add Mapster to service collection:

services.AddMapster();

And use it with DI in your Project:

public class Test
{
    public Test(IMapper mapper)
    {
        var sourceObject = mapper.Adapt<Destination>();
    }
}

Queryable Extensions

Mapster also provides extensions to map queryables.

using (MyDbContext context = new MyDbContext())
{
    // Build a Select Expression from DTO
    var destinations = context.Sources.ProjectToType<Destination>().ToList();

    // Versus creating by hand:
    var destinations = context.Sources.Select(c => new Destination {
        Id = c.Id,
        Name = c.Name,
        Surname = c.Surname,
        ....
    })
    .ToList();
}

Generating models & mappers

No need to write your own DTO classes. Mapster provides Mapster.Tool to help you generating models. And if you would like to have explicit mapping, Mapster also generates mapper class for you.

[AdaptTo("[name]Dto"), GenerateMapper]
public class Student {
    ...
}

Then Mapster will generate for you:

public class StudentDto {
    ...
}
public static class StudentMapper {
    public static StudentDto AdaptToDto(this Student poco) { ... }
    public static StudentDto AdaptTo(this Student poco, StudentDto dto) { ... }
    public static Expression<Func<Student, StudentDto>> ProjectToDto => ...
}

What's new

Why Mapster?

Performance & Memory efficient

Mapster was designed to be efficient on both speed and memory. The repository includes a benchmark project in src/Benchmark that compares the local Mapster build, its compiler variants, and other modern mapping libraries like AutoMapper, Mapperly, and Facet.

The snapshot below shows the FlatTypes scenario (Person -> PersonDTO), a best-case DTO with simple property-to-property mapping and no nested objects or collections.

Note

More complex object shapes can change the relative results. See the complete benchmark results for ComplexTypes, RecursiveTypes, and TotalAllTypes.

MethodMapOperationsMeanStdDevErrorNs/MapRatioGen0AllocatedAlloc RatioBytes/Map
Mapster 10.0.810000006.849 ms0.6851 ms1.0358 ms6.8491.01478176.29 MB1.0080
Mapster 10.0.8 (Roslyn)10000006.579 ms0.2782 ms0.4206 ms6.5790.97478176.29 MB1.0080
Mapster 10.0.8 (FEC)10000006.549 ms0.9130 ms1.3803 ms6.5490.97478176.29 MB1.0080
Mapster 10.0.8 (Codegen)10000005.868 ms0.3266 ms0.5488 ms5.8680.86478176.29 MB1.0080
AutoMapper 14.0.0100000029.645 ms0.8963 ms1.5062 ms29.6454.37475076.29 MB1.0080
Facet 6.5.510000007.801 ms1.0231 ms1.5467 ms7.8011.158601137.33 MB1.80144
Facet 6.5.5 (Compiled Projection)10000005.508 ms0.7064 ms1.0679 ms5.5080.81478176.29 MB1.0080
Mapperly 4.3.110000006.521 ms0.8369 ms1.2652 ms6.5210.96478176.29 MB1.0080

Step into debugging

Step-into debugging lets you debug your mapping and inspect values just like your code.

inspect-generated-source-code-while-debugging

Code Generation

Code generation allows you to

  • Validate mapping at compile time
  • Getting raw performance
  • Seeing your mapping code & debugging
  • Finding usage of your models' properties

There are currently two tools which you can choose based on your preferences.

Change logs

https://github.com/MapsterMapper/Mapster/releases

Usage Guides with Translations

Acknowledgements

JetBrains kindly provides Mapster with a free open-source licence for their Resharper and Rider.

  • Resharper makes Visual Studio a much better IDE
  • Rider is fast & powerful cross platform .NET IDE