Problem ignoring nested properties with Automapper

I am having a problem when I try to ignore properties inside properties. eg.

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

I get the following exception:

{"Expression 'dest => dest.NodeType.EntityType.Properties' must resolve to top-level member.\r\nParameter name: lambdaExpression"}

Any idea?

+1
source share
1 answer

Well, I managed to figure it out myself. I have to specify the parameters of the nested property in my own dto mapping. However, let me know if there is another better way to do this.

  Mapper.CreateMap<EntityType, EntityTypeDto>()
                .ForMember(dest => dest.Properties, opt => opt.Ignore());               
            Mapper.CreateMap<Node, NodeDto>()
                .ForMember(dest => dest.ChildNodes, opt => opt.Ignore());
+1
source

All Articles