AutoMapper Map Child Property that also has a map defined

You just need to specify that in the mapping:

Mapper.CreateMap<DomainClass, Child>();
Mapper.CreateMap<DomainClass, Parent>()
      .ForMember(d => d.Id, opt => opt.MapFrom(s => s.Id))
      .ForMember(d => d.A, opt => opt.MapFrom(s => s.A))
      .ForMember(d => d.Child, 
                 opt => opt.MapFrom(s => Mapper.Map<DomainClass, Child>(s)));

Just map the child using self. Tested with AutoMapper 6.1.1.

        CreateMap<DomainClass, Child>();
        CreateMap<DomainClass, Parent>()
            .ForMember(d => d.Child, opt => opt.MapFrom(s => s));

Tags:

C#

Automapper