Automapper map into nested class

前端 未结 3 365
抹茶落季
抹茶落季 2020-12-14 18:56

I have 1 class that I need t map into multiple classes, for eg.

This is the source that I\'m mapping from(view model):

public class UserBM
{
    publ         


        
3条回答
  •  情歌与酒
    2020-12-14 19:36

    Define two mappings, both mapping from the same source to different destinations. In the User mapping, map the Location property manually using Mapper.Map(...)

    Mapper.CreateMap();
    Mapper.CreateMap()
        .ForMember(dest => dest.Location, opt => 
             opt.MapFrom(src => Mapper.Map(src));
    

提交回复
热议问题