Issue with Ignoring nested Properties using Automa

2019-07-23 16:07发布

问题:

I have ran into an issue where I am trying to ignore properties within properties. e.g.

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

I get following exception:

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

Any idea?

回答1:

Well I have managed to figure it out by myself. I have to specify the nested property options in its own dto mapping. However let me know if there is another better way of doing this

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


标签: AutoMapper