自动映射从不同对象类型到有条件地源

时间:2015-01-29 10:30:21

标签: mapping conditional automapper

我正在尝试根据条件从不同的源属性映射viewmodel属性。我希望根据类型从ContactIndividual或Individual映射详细信息。我收到错误 - Individual和ContactIndividual之间没有隐式转换

Mapper.CreateMap<Individual, MyParentVM>()
        .ForMember(x => x.Number, o => o.MapFrom(s => s.Code))
        .ForMember(x => x.Details, o => o.MapFrom(s => (s.Type == AType.Individual) ? s as Individual: s.Contact as ContactIndividual));
Mapper.CreateMap<Individual, MyDetailsVM>();
Mapper.CreateMap<ContactIndividual, MyDetailsVM>();

0 个答案:

没有答案