欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

.NET CORE中使用AutoMapper進(jìn)行對(duì)象映射的方法

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

簡介

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

平臺(tái)支持:

  • .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();
 //添加對(duì)AutoMapper的支持
 services.AddAutoMapper();
}

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

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

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

IMapper _mapper;

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

單個(gè)對(duì)象轉(zhuǎn)換

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

集合對(duì)象轉(zhuǎn)換

總結(jié)

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

相關(guān)文章

最新評(píng)論