.net core3.1 AutoMapper
1.新增nuget包
AutoMapper.Extensions.Microsoft.DependencyInjection
2.startup.cs
using AutoMapper;
using System;
//...
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
3.新建資料夾Profile(配置對映),新建studentprofile.cs
public class studentprofile:Profile//繼承Automapper的Profile
{
public studentprofile()
{
CreateMap<Student, studentdto>()
.ForMember(dest=>dest.xingbie//目標屬性名xingbie
, opt=>opt.MapFrom(a=>a.sex));//遠屬性名sex
}
}
實體類試例
[Table("Student")]
public class Student
{
[Key]
public int sid { get; set; }
public int sex { get; set; }
public int cid { get; set; }
}
//...
public class studentdto
{
public int sid { get; set; }
public int xingbie { get; set; }
}
4.Controllers
private readonly Istudent _stu;
private readonly IMapper _map;
public TestController(Istudent istudent,IMapper map)
{
_stu = istudent;
_map = map;
}
[HttpGet]
public List<studentdto> Get()
{
return _map.Map<List<studentdto>>(_stu.find());//
}
相關文章
- .net framework autoMapper使用FrameworkAPP
- .net Core 使用AutoMapperAPP
- .NET Core3.1 Dotnetty實戰系列視訊Netty
- .net core中使用AutomapperAPP
- net core3.1整合收集日誌- sentry
- .NET Core Dto對映(AutoMapper)APP
- .Net Mvc AutoMapper簡單使用MVCAPP
- .Net core 中 AutoMapper的應用APP
- ASP.NET.Core中使用AutoMapperASP.NETAPP
- .Net Core中更高階的AutoMapper示例APP
- .NET Core 中AutoMapper的配置及使用APP
- .NET Core 中依賴注入 AutoMapper 小記依賴注入APP
- asp.net core 3.1.x 中使用AutoMapperASP.NETAPP
- 在ASP.NET Core MVC 2.2 中使用AutoMapperASP.NETMVCAPP
- .NET CORE 中使用AutoMapper進行物件對映APP物件
- Asp.NetCore之AutoMapper進階篇ASP.NETNetCoreAPP
- Asp.NetCore之AutoMapper基礎篇ASP.NETNetCoreAPP
- AutoMapperAPP
- .Net Core AutoMapper自定義擴充套件方法的使用APP套件
- .NET CORE AUTOMAPPER 對映一個類的子類APP
- 如何在 .NetCore 中使用 AutoMapper 高階功能NetCoreAPP
- ASP.NET Core 中的物件對映之 AutoMapperASP.NET物件APP
- asp.net core3.1 實戰開發(中介軟體的詳解)ASP.NET
- .net core3.1 abp動態選單和動態許可權(思路) (二)
- .Net Core3.1 + EF Core + LayUI 封裝的MVC版後臺管理系統UI封裝MVC
- ASP.NET Core3.1使用Identity Server4建立Authorization Server-1ASP.NETIDEServer
- ASP.NET Core3.1使用Identity Server4建立Authorization Server-2ASP.NETIDEServer
- AutoMapper(七)APP
- AutoMapper(六)APP
- AutoMapper(五)APP
- AutoMapper(四)APP
- AutoMapper(三)APP
- AutoMapper(二)APP
- AutoMapper(一)APP
- asp.net core3.1 實戰開發(驗證碼的封裝和使用)ASP.NET封裝
- asp.net core3.1 實戰開發(授權,鑑權封裝詳解)ASP.NET封裝
- 淺入 AutoMapperAPP
- Asp.Net專案釋出 到 IIS、 Core3.1 釋出到 IIS CentOS8.xASP.NETCentOS