0

I have this auto mapper that is mapping enum type,

Mapper.CreateMap<SASEMProfileVm, SASEMMembersDto>()
      .ForMember(dest => dest.ProfessionalHistoryDto.CarryingTime, 
                  opt => opt.MapFrom(src => src.ProfessionalHistoryCarryingTime))

CarryingTime is of type TimePeriod and ProfessionalHistoryCarryingTime is also from type TimePeriod

when i run it it gives me this error

Expression 'dest => Convert(dest.ProfessionalHistoryDto.CarryingTime)' must resolve to top-level member and not any child object's properties. Use a custom resolver on the child type or the AfterMap option instead. Parameter name: lambdaExpression

What should i do to solve it?

stuartd
  • 70,509
  • 14
  • 132
  • 163

1 Answers1

2

Automapper cannot define mapping for multilevel objects. You can use .AfterMap

Mapper.CreateMap<SASEMProfileVm, SASEMMembersDto>()
      .AfterMap((s, d) => 
          d.ProfessionalHistoryDto.CarryingTime = s.ProfessionalHistoryCarryingTime);
stuartd
  • 70,509
  • 14
  • 132
  • 163
wonderbell
  • 1,126
  • 9
  • 19