5

I have a Conference that has a list of a related Conference. I want the top level conference to give a list of its related conferences but for it to stop there.

I tried the following but when setting maxDepth to 1 I get null for the first child. When setting maxDepth to 2 I get a stockoverflow. If any one knows how to fix this help is appreciated. Thanks, Alex

 Mapper.CreateMap<Data.Conference, Dto.Conference>().MaxDepth(2);

First time using automapper, let me try to explain what I'm trying to solve with MaxDepth:

Conference has a list of associated Conference. So Conference A has an associated Conference B. And Conference B has an associated Conference A.

Now I am sending a list of Conferences with WCF. Clearly sending Conference A over the wire will result in a stack overflow. Is it possible to prevent this with automapper while keeping the first level of associated conferences

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
Alex808
  • 109
  • 9
  • Hmmm you may have found a bug with AutoMapper. I recreated your issue with NULL for the first child. However, when I set MaxDepth to 2, it just pushed the NULL child down a level, it didn't Stackoverflow. I'm using AutoMapper 3.3.1.0 - Are you auto-mapping POCOs in memory at that point or are you using Project on an IQueryable in EF? – Adam Feb 25 '15 at 16:14
  • I edited my question. auto-mapping POCOs in memory.. thanks for the help – Alex808 Feb 25 '15 at 18:02
  • 1
    Here's an answer that may suggest a different approach http://stackoverflow.com/questions/11505128/circular-reference-causing-stack-overflow-with-automapper – Steve Mitcham Feb 25 '15 at 18:04

0 Answers0