I have two classes with a many-to-many relationship, all the mapping is ready, the insert is working, but when I try to do AutoMapper it goes into an infinite loop.
Workflow:
public class Workflow : Elemento
{
public IList<EventoWorkflow> EventosWorkflow;
}
EventWorkflow:
public class EventoWorkflow : Evento
{
public IList<Workflow> Workflows;
}
I tried several things that I found on the internet to try to make it work but none of them worked, the last attempt I made was like this:
Workflow - > WorkflowDTO
Mapper.CreateMap<Workflow, WorkflowDTO>()
.ForMember(x => x.EventosWorkflow, m => m.MapFrom(w => w.EventosWorkflow.Select(y => y.ActualObject).ToList()));
EventWorkflow - > EventWorkflowDTO
Mapper.CreateMap<EventoWorkflow, EventoWorkflowDTO>()
.ConstructUsing(x => new EventoWorkflowDTO(x.CodigoEvento, AutoMapper.Mapper.Map<IList<Workflow>, List<WorkflowDTO>>(x.Workflows)));
But he still gives the error:
An unhandled exception of type 'System.StackOverflowException'
Does anyone know how I can solve this problem?