I have tried many options to get Automapper to correctly map Parent / Child relationships.
Model:
//Entity
public class WorkArea
{
public Guid Id;
public Name {get;set;}
public Guid? ParentWorkAreaId {get;set;} //for entity Framework Foreign Key
public WorkArea ParentWorkArea {get;set;}
public ICollection<WorkArea> ChildWorkareas {get;set;}
}
//DTO
public class WorkAreaDto
{
public Guid Id;
public Name {get;set;}
public Guid? ParentWorkAreaId {get;set;} //for entity Framework Foreign Key
public WorkAreaDto ParentWorkArea {get;set;}
public ICollection<WorkAreaDto> ChildWorkareas {get;set;}
}
This mapping causes a Stack Overflow:
Mapper.CreateMap<WorkArea,WorkAreaDto>();
I tried something exactly like this and had the same error
I then created a custom TypeConverter, but not only do I have to write recursive methods for children, but also parents. Just seems like a lot of work do get this to map correctly. Not sure if I am doing something wrong. I am using 2.0
Update: I think my issue is the System.Data.Entity.DynamicProxies generated by Entity Framework.