简介
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.
官网:http://automapper.org/
文档:https://automapper.readthedocs.io/en/latest/index.html
GitHub:https://github.com/AutoMapper/AutoMapper/blob/master/docs/index.rst
平台支持:
使用
Nuget安装
AutoMapper AutoMapper.Extensions.Microsoft.DependencyInjection //依赖注入AutoMapper,需要下载该包。
在Startup中添加AutoMapper
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //添加对AutoMapper的支持 services.AddAutoMapper(); }
创建AutoMapper映射规则
public class AutoMapperConfigs:Profile { //添加你的实体映射关系. public AutoMapperConfigs() { CreateMap<DBPoundSheet, PoundSheetViewModel>(); CreateMap<PoundSheetViewModel, DBPoundSheet>(); } }
在构造函数中注入你的IMapper
IMapper _mapper; public PoundListController(IMapper mapper) { _mapper = mapper; }
单个对象转换
//typeof(model)="PoundSheetViewModel" DBPoundSheet dBPoundSheet = _mapper.Map<DBPoundSheet>(model);
集合对象转换
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对站长技术的支持。
本文实例为大家分享了vue实现按钮切换图片的具体代码,供大家参考,具体内容如下...
目录 读者基础 ?微服务架构梳理 https://www.coder4.com/homs_online/ ? ? 读者...
MFC项目在vs2017编译正常无报错,但是升级vs2019后一打开项目就报如下错误。 项...
由于固态驱动器(SSD)的速度比传统的硬盘驱动器(HDD)快得多,并且价格越来越便宜...
这5个PHP编程中的不良习惯,一定要改掉 PHP世界上最好的语言! 测试循环前数组是...
今天看到个不错的网页播放器,感觉不错,大家可以测试 我写的一个播放器网页: ...
目录 1. C语言文件接口(库函数) 1.1 fopen 1.2 fclose 1.3 fread 1.4 fwrite 1.5...
本文实例为大家分享了javascript实现倒计时提示框的具体代码,供大家参考,具体...
在大三的时候,一直就想搭建属于自己的一个博客,但由于各种原因,最终都不了了...
首先到这里下载其源码。里面东西挺多的,我们基本上可以把它放到两个文件夹就是...