AutoMapper
A convention-based object-object mapper.
AutoMapper uses a fluent configuration API to define an object-object mapping strategy. AutoMapper uses a convention-based matching algorithm to match up source to destination values. AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer.
New to AutoMapper? Check out the Getting Started Guide page first.
- Configuration
- Configuration Validation
- Dependency Injection
- Projection
- Nested Mappings
- Lists and Arrays
- Construction
- Flattening
- Reverse Mapping and Unflattening
- Mapping Inheritance
- Attribute Mapping
- Dynamic and ExpandoObject Mapping
- Open Generics
- Queryable Extensions
- Expression Translation (UseAsDataSource)
- AutoMapper.Extensions.EnumMapping
- API Changes
- 13.0 Upgrade Guide
- AutoMapper now targets .Net 6
AddAutoMapper
is part of the core package and the DI package is discontinuedIMapper
has nullable annotationsAllowAdditiveTypeMapCreation
was removed- ProjectTo runtime polymorphic mapping with Include/IncludeBase
Context.State
similar toContext.Items
- Custom Equals/GetHashCode for source objects
- 12.0 Upgrade Guide
- 11.0 Upgrade Guide
- AutoMapper now targets .Net Standard 2.1 and doesn’t work on .Net Framework
ForAllMaps
,ForAllPropertyMaps
,Advanced
and other “missing” APIs- Mapping into existing collections
CreateProjection
System.ComponentModel.TypeConverter
is no longer supported- Generating interface proxies is disabled by default
MapToAttribute
andIgnoreMapAttribute
were removed- Global pre and postfixes are now applied in all maps
ForAllOtherMembers
was removed- C# Indexers (
Item
property) - Configuration performance
- 10.0 Upgrade Guide
- All collections are mapped by default, even if they have no setter
- Matching constructor parameters will be mapped from the source, even if they are optional
Context.Mapper.Map
overloads that receive a context were removedUseDestinationValue
is now inherited by defaultAllowNull
allows you to override per memberAllowNullDestinationValues
andAllowNullCollections
- The
ResolutionContext
no longer has a public constructor - Mapping from
dynamic
in .NET 4.6.1 - Source validation
MaxDepth
- String based
MapFrom
-s are reversed now, also applies to attribute mapping ReverseMap
will also reverse the naming conventions
- 9.0 Upgrade Guide
- 8.1.1 Upgrade Guide
- 8.0 Upgrade Guide
- 5.0 Upgrade Guide
Examples
The source code contains unit tests for all of the features listed above. Use the GitHub search to find relevant examples.
Housekeeping
The latest builds can be found at NuGet
The dev builds can be found at MyGet
The discussion group is hosted on Google Groups