Tag: automapper 5

使用AutoMapper进行集合的多态映射

TL; DR:我遇到了多态映射问题。 我用一个测试套件制作了一个github repo来说明我的问题。 请在此处找到: LINK TO REPO 我正在努力实现保存/加载function。 为了实现这一点,我需要确保我序列化的域模型以序列化友好的方式表示。 为了实现这一点,我创建了一组DTO,其中包含进行有意义的保存或加载所需的最小信息集。 对于域名这样的东西: public interface IDomainType { int Prop0 { get; set; } } public class DomainType1 : IDomainType { public int Prop1 { get; set; } public int Prop0 { get; set; } } public class DomainType2 : IDomainType { public int Prop2 { get; […]

迁移到AutoMapper 5 – 循环引用

尝试在AutoMapper 5中映射之前使用AutoMapper 4工作的东西时,我遇到了System.StackOverflowException 。 谷歌搜索后,我发现它是由循环引用引起的。 AutoMapper文档说: 以前,AutoMapper可以通过跟踪映射的内容来处理循环引用,并在每个映射上检查源/目标对象的本地哈希表,以查看该项是否已映射。 事实certificate,这种跟踪非常昂贵,您需要使用PreserveReferences选择使用圆形贴图才能工作。 或者,您可以配置MaxDepth: // Self-referential mapping cfg.CreateMap().MaxDepth(3); // Circular references between users and groups cfg.CreateMap().PreserveReferences(); 所以我将.MaxDepth(3)添加到我的代码中,它现在再次运行。 但是我没有说明真正的问题是什么以及我通过添加线路做了什么:) 我的问题: 什么意思是关于Category / CategoryDto的’循环引用’? 到底是什么.MaxDepth() ? 为什么样品中使用了3? 什么是.PreserveReferences() ?