我正在尝试使用自动映射器为父对象创建单个映射,并在其子对象中重用它。
对于子属性,我只想映射额外的字段。
这可能吗?我的代码看起来像这样
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
为什么它一直告诉我父母的属性没有映射?然而,我认为我将它们包含在 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)