自动传递器继承 - 重用地图

Chr*_*elt 8 c# automapper

我试图使用automapper为父对象创建一个映射,并在其子对象中重用它.

对于子属性,我只想映射额外的字段.

这可能吗?我的代码看起来像这样

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
Run Code Online (Sandbox Code Playgroud)

为什么它一直告诉我父母属性没有映射?然而,我以为我把它们包含在CreateCalculationMap(消息)中; 其中包含

Mapper.CreateMap<QuoteMessage, CalculationBase>() ()
Run Code Online (Sandbox Code Playgroud)

Chr*_*elt 6

仅供我,我想出来了

 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
Run Code Online (Sandbox Code Playgroud)