dto

1、nuget AutoMapper for .net core

2、依赖注入 

1 // 环境注入
2 // 参数类型是Assembly类型的数组 表示AutoMapper将在这些程序集数组里面遍历寻找所有继承了Profile类的配置文件
3 // 在当前作用域的所有程序集里面扫描AutoMapper的配置文件
4 builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

3、书写转换的dto实体类

4、设定转换的方式

public class ListProfile : Profile
{
    public ListProfile()
    {
    // 1、需要转换的类  2、目标类 CreateMap
<Models.BaseArea, Dtos.BaseAreaSelect>() .ForMember// 自定义 ( a => a.shortName, b => b.MapFrom(c => c.Code + c.CreateUserName) ); } }

 

posted @ 2022-05-02 10:58  changsen-  阅读(179)  评论(0编辑  收藏  举报