public class AutoMapperProfile : AutoMapper.Profile { public AutoMapperProfile() { //实体字段一致情况 <TSource, TDestination> CreateMap<SelfRequest,entity_self > (); } }
//automapper services.AddAutoMapper(c=>c.AddProfile(new AutoMapperProfile()));
private readonly IMapper _mapper; public SelfController(ILogger<SelfController> logger, IMapper mapper) { _logger = logger; _mapper = mapper; }
[HttpPost("Save")] public async Task<WebApiResult> Save([FromBody] SelfRequest request) { var enity = _mapper.Map<entity_self>(request); }
原文:https://www.cnblogs.com/personblog/p/14863885.html