Problem with Many Interface Automapper for Many C#

Asked

Viewed 248 times

1

I have two classes with a relation of many to many, all the mapping is already ready, the insertion is working, but when I try to do the Automapper it enters an infinite loop.

Workflow:

    public class Workflow : Elemento
    {
        public IList<EventoWorkflow> EventosWorkflow;
    }

Eventoworkflow:


    public class EventoWorkflow : Evento
    {
        public IList<Workflow> Workflows;
    }

I tried several things 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()));

Eventoworkflow -> Eventoworkflowdto


    Mapper.CreateMap<EventoWorkflow, EventoWorkflowDTO>()
                    .ConstructUsing(x => new EventoWorkflowDTO(x.CodigoEvento, AutoMapper.Mapper.Map<IList<Workflow>, List<WorkflowDTO>>(x.Workflows)));

But still he keeps making the mistake:

An unhandled Exception of type 'System.Stackoverflowexception'

Does anyone know how I can solve this problem?

  • Post also your DTO classes, please.

1 answer

0


Just give a .Ignore() in the related classes to stop the infinite loop. With that, you’ll make relationships come true null, then you should work with the data this way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.