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)));

 

posted @ 2019-10-14 16:24  无语1994  阅读(828)  评论(0编辑  收藏  举报