本文介绍了使用自动映射器忽略嵌套属性的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个问题,我试图忽略属性中的属性.例如
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());
我收到以下异常:
{"Expression 'dest => dest.NodeType.EntityType.Properties' must resolve to top-level member.\r\nParameter name: lambdaExpression"}
有什么主意吗?
推荐答案
好吧,我已经设法自己弄清楚了.我必须在其自己的dto映射中指定嵌套属性选项.但是,请告诉我是否还有另一种更好的方法
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());
这篇关于使用自动映射器忽略嵌套属性的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!