AutoMapper is a simple little library built to solve a deceptively complex problem - getting rid of code that mapped one object to another. This type of code is rather dreary and boring to write, so why not invent a tool to do it for us?
This is the main repository for AutoMapper, but there's more:
- EF6 Extensions
- IDataReader/Record Extensions
- Collection Extensions
- Microsoft DI Extensions
- Expression Mapping
- Enum Extensions
First, configure AutoMapper to know what types you want to map, in the startup of your application:
var configuration = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Foo, FooDto>();
cfg.CreateMap<Bar, BarDto>();
});
// only during development, validate your mappings; remove it before release
configuration.AssertConfigurationIsValid();
// use DI (http://docs.automapper.org/en/latest/Dependency-injection.html) or create the mapper yourself
var mapper = configuration.CreateMapper();
Then in your application code, execute the mappings:
var fooDto = mapper.Map<FooDto>(foo);
var barDto = mapper.Map<BarDto>(bar);
Check out the getting started guide. When you're done there, the wiki goes in to the nitty-gritty details. If you have questions, you can post them to Stack Overflow or in our Gitter.
First, install NuGet. Then, install AutoMapper from the package manager console:
PM> Install-Package AutoMapper
First check if it's already fixed by trying the MyGet build.
You might want to know exactly what your mapping does at runtime.
If you're still running into problems, file an issue above.
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.
AutoMapper is Copyright © 2009 Jimmy Bogard and other contributors under the MIT license.
This project is supported by the .NET Foundation.