亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

.NET CORE中使用AutoMapper進行對象映射的方法

 更新時間:2019年04月17日 08:27:51   作者:進擊的辣條  
這篇文章主要給大家介紹了關(guān)于.NET CORE中使用AutoMapper進行對象映射的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用.NET CORE具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧

簡介

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.

官網(wǎng):http://automapper.org/

文檔:https://automapper.readthedocs.io/en/latest/index.html

GitHub:https://github.com/AutoMapper/AutoMapper/blob/master/docs/index.rst

平臺支持:

  • .NET 4.6.1+
  • .NET Standard 2.0+ https://docs.microsoft.com/en-us/dotnet/standard/net-standard

使用

Nuget安裝

AutoMapper  
AutoMapper.Extensions.Microsoft.DependencyInjection //依賴注入AutoMapper,需要下載該包。

在Startup中添加AutoMapper

public void ConfigureServices(IServiceCollection services)
{
 services.AddMvc();
 //添加對AutoMapper的支持
 services.AddAutoMapper();
}

創(chuàng)建AutoMapper映射規(guī)則

public class AutoMapperConfigs:Profile
{
 //添加你的實體映射關(guān)系.
 public AutoMapperConfigs()
 {
  CreateMap<DBPoundSheet, PoundSheetViewModel>();
  CreateMap<PoundSheetViewModel, DBPoundSheet>();
 }
}

在構(gòu)造函數(shù)中注入你的IMapper

IMapper _mapper;

public PoundListController(IMapper mapper)
{
 _mapper = mapper;
}

單個對象轉(zhuǎn)換

//typeof(model)="PoundSheetViewModel"
DBPoundSheet dBPoundSheet = _mapper.Map<DBPoundSheet>(model);

集合對象轉(zhuǎn)換

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論