automapper 源中有多个属性类映射到同一个 目标中

CreateMap<TempBranchActivity, BranchActivityOutput>()
                .ConstructUsing((src, ctx) => ctx.Mapper.Map<BranchActivityOutput>(src.BranchActivityInfo))
                .ForMember(m => m.ApplyNum, opt => opt.MapFrom(m => m.BranchActivityApplyDto.ApplyNum));

  

用automapper ContructUsing 构造器。返回一个目标实例

这里就可以进行map . 

以上方法可以写成

CreateMap<TempBranchActivity, BranchActivityOutput>()
                .ConstructUsing((src, ctx) =>
                    ctx.Mapper.Map<BranchActivityOutput>(ctx.Mapper.Map<BranchActivityOutput>(src.BranchActivityInfo)));
原文地址:https://www.cnblogs.com/quan01994/p/11672159.html