.NET CORE中使用AutoMapper进行对象映射的方法
简介
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 plex object models to DTOs and other simple objects, whose design is better suited for serialization, munication, messaging, or simply an anti-corruption layer between the domain and application layer.
官网http://automapper./
文档https://automapper.readthedocs.io/en/latest/index.html
GitHubhttps://github./AutoMapper/AutoMapper/blob/master/docs/index.rst
平台支持
- .NET 4.6.1+
- .NET Standard 2.0+ https://docs.microsoft./en-us/dot/standard/-standard
使用
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);
集合对象转换
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对狼蚁SEO的支持。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指