我正在尝试使用自动映射器为父对象创建单个映射,并在其子对象之间重用此映射。
对于子属性,我只想映射额外的字段。
这可能吗?我的代码看起来像这样
CreateCalculationMap(message); ---- This does the BASE parent mappping.
Mapper.CreateMap<QuoteMessage, CalculationGipMessage>() -- This is the child.
.Include<QuoteMessage, CalculationBase>() -- Include the parent?
.ForMember(a => a.OngoingCommission, b => b.MapFrom(c => c.OngoingASF)) - Child
.ForMember(a => a.SpecialRate, b => b.MapFrom(c => c.BlahBlah))); - Child
为什么总是告诉我未映射 parent 属性?但是,我以为我将它们包括在CreateCalculationMap(message);中。其中包含
Mapper.CreateMap<QuoteMessage, CalculationBase>() ()
最佳答案
仅供引用
public static IMappingExpression<A, T> ApplyBaseQuoteMapping<A, T>(this IMappingExpression<A, T> iMappingExpression)
where A : QuoteMessage
where T : CalculationGipMessage
{
iMappingExpression
.ForMember(a => a.LoginUserName, b=> b.MapFrom(c => c.LoginUserName))
.ForMember(a => a.AssetTestExempt, b => b.Ignore())
;
return iMappingExpression;
}
Mapper.CreateMap<QuoteMessage, CalculationGipMessageChild>()
.ApplyBaseQuoteMappingToOldCol()
// do other mappings here