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?
Automapper cannot define mapping for multilevel objects. You can use .AfterMap
Mapper.CreateMap<SASEMProfileVm, SASEMMembersDto>()
.AfterMap((s, d) =>
d.ProfessionalHistoryDto.CarryingTime = s.ProfessionalHistoryCarryingTime);