I am working on an application which includes a service which interfaces with a database.
When I save certain classes, the return mapping causes a StackOverflowException
Here is the context
The dto classes are generated automatically by ado.Net entity.
I get circular references.
AutoMapper version : 6.2.2
Sample:
public partial class dim_site
{ ...
public virtual ICollection<dim_site_caracteristiques> dim_site_caracteristiques { get; set; }
}
public partial class dim_site_caracteristiques
{ ...
public virtual dim_site dim_site { get; set; }
public virtual ICollection<lien_caracteristique_tarif> lien_caracteristique_tarif { get; set; }
}
public partial class lien_caracteristique_tarif
{ ...
public virtual dim_site_caracteristiques dim_site_caracteristiques { get; set; }
}
With these classes, AutoMapper throws a StackOverflowException
Sample:
// I save a dim_site in the database.
// The mapper works in this direction
Communication.Contract.Mangrove.dim_site result = SaveSite(Context, AutoMapper.Mapper.Map<Communication.Contract.Mangrove.dim_site>(site)
// We map the result in the other direction. There the StackOverflowException exception occurs
return AutoMapper.Mapper.Map<Business.Service.Dto.Canopee.dim_site>(result);