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.html
官网:http://automapper.org/ios
文档:https://automapper.readthedocs.io/en/latest/index.htmlgit
GitHub:https://github.com/AutoMapper/AutoMapper/blob/master/docs/index.rstgithub
平台支持:app
AutoMapper AutoMapper.Extensions.Microsoft.DependencyInjection //依赖注入AutoMapper,须要下载该包。
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //添加对AutoMapper的支持 services.AddAutoMapper(); }
public class AutoMapperConfigs:Profile { //添加你的实体映射关系. public AutoMapperConfigs() { CreateMap<DBPoundSheet, PoundSheetViewModel>(); CreateMap<PoundSheetViewModel, DBPoundSheet>(); } }
IMapper _mapper; public PoundListController(IMapper mapper) { _mapper = mapper; }
//typeof(model)="PoundSheetViewModel" DBPoundSheet dBPoundSheet = _mapper.Map<DBPoundSheet>(model);