So the error is this: Expression must resolve to top-level member and not any child object's properties.
Remuneration in the DTO is a Enum. ContractEntity uses a Remuneration that is a ComplexType.
The code throwing the error:
Mapper.CreateMap<ContractDTO, ContractEntity>() .ForMember(d => d.Remuneration.ContractType, s => s.MapFrom(z => z.ContractType)) .ForMember(d => d.Remuneration.Currency, s => s.MapFrom(z => z.Currency)) .ForMember(d => d.Remuneration.RateUnit, s => s.MapFrom(z => z.RateUnit)); Entity Framework complex type:
[ComplexType] public class Remuneration { public decimal Amount { get; set; } public int Currency { get; set; } public int RateUnit { get; set; } public int ContractType { get; set; } } Because I want the destination (ContractEntity) to use the integer values, I thought I could just cast the source enum to the destination integer like this:
.ForMember(d => d.Remuneration.ContractType, s => s.MapFrom(z => (int)z.ContractType)) .. obviously I cant, and was hoping that someone could clarify why this doesn't work..