Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos

后端 未结 5 840
轻奢々
轻奢々 2020-12-07 20:23

I am having an issue using AutoMapper (which is an excellent technology) to map a business object to a DTO where I have inheritance off of an abstract base class within a co

5条回答
  •  借酒劲吻你
    2020-12-07 21:21

    This answer comes 'a bit' late as I've just faced the same issue with EF4 POCO proxies.

    I solved it using a custom converter that calls Mapper.DynamicMap(object source) to invoke the runtime type conversion, rather than the .Include().

    It works fine for me.

    In your case you would define the following converter:

    class PaymentConverter : ITypeConverter {
        public DtoPayment Convert( ResolutionContext context ) {
            return Mapper.DynamicMap( context.SourceValue );
        }
    }
    

    And then:

    Mapper.CreateMap().ConvertUsing();
    Mapper.CreateMap();
    Mapper.CreateMap();
    

提交回复
热议问题