更新时间:2022-04-07 00:55:16
使用 @Jasen 评论我得到了它的工作.主要问题是我的映射方向相反.官方文档中的这句话解决了问题:
Using @Jasen comments I got it working. The main problem was that I am mapping in a reversed direction. This sentence in official documentation solves the problem:
Unflattening 仅针对 ReverseMap
配置.如果你想要unflattening,你必须配置Entity
-> Dto
然后调用ReverseMap
从Dto
-> Entity
.
Unflattening is only configured for
ReverseMap
. If you want unflattening, you must configureEntity
->Dto
then callReverseMap
to create an unflattening type map configuration from theDto
->Entity
.
这是链接:
https://github.com/AutoMapper/AutoMapper/blob/master/docs/Reverse-Mapping-and-Unflattening.md
换句话说,为了不讨人喜欢地工作,我必须(或必须)朝这个方向映射:
In other words, to get unflattering to work, I have (or must) to map in this direction:
CreateMap<HierarchicalObject, FlattenedObject>()
.ReverseMap();