tags:

views:

69

answers:

1

Hi guys,

I have a scenario where I would like to ignore some properties of classes defined in base class.

I have an initial mapping like this

   Mapper.CreateMap<Node, NodeDto>()
                .Include<Place, PlaceDto>()
                .Include<Asset, AssetDto>();

Then I customised it more like this to ignore one of the properties defined in base class NodeDto

 Mapper.CreateMap<Node, NodeDto>()
                .ForMember(dest => dest.ChildNodes, opt => opt.Ignore());

However when I try to map, Place to PlaceDto or Asset to AssetDto, the ChildNodes property does not get ignored. So I ended up doing soething like this

  Mapper.CreateMap<Node, NodeDto>()
                .ForMember(dest => dest.ChildNodes, opt => opt.Ignore());
            Mapper.CreateMap<Place, PlaceDto>()
                .ForMember(dest => dest.ChildNodes, opt => opt.Ignore());
            Mapper.CreateMap<Asset, AssetDto>()
                .ForMember(dest => dest.ChildNodes, opt => opt.Ignore());

Since I have lots of child classes for NodeDto, the above process is cumbersome, and I would like to know if there is a better approach?

Thanks Nabeel

+1  A: 

sorry but, no, there isn't any other way, that's how automapper works

Omu

related questions