Circular reference causing stack overflow with Automapper

后端 未结 5 956
不思量自难忘°
不思量自难忘° 2020-11-29 09:29

I\'m using Automapper to map my NHibernate proxy objects (DTO) to my CSLA business objects

I\'m using Fluent NHibernate to create the mappings - this is working fine

5条回答
  •  离开以前
    2020-11-29 10:00

    I was having the same issue and solved it by downgrading to version 4.2.1. apparently the checks for circular references was expensive so they made it default to not check. Migrating to AutoMapper 5 - Circular references

    Supposedly these are supposed to be the settings methods for v 5+ but it didn't work for my data model because we opt'd for complex dto relationships instead of single use dtos for each action.

    // Self-referential mapping
    cfg.CreateMap().MaxDepth(3);
    
    // Circular references between users and groups
    cfg.CreateMap().PreserveReferences();
    

    http://docs.automapper.org/en/stable/5.0-Upgrade-Guide.html#circular-references

    Automapper is supposed to be able to statically determine if the circular reference settings in v6.1+, So if it doesn't work for you automatically in version v6.1+ contact the automapper team.

提交回复
热议问题