'Does automapper support mapping collections with circular references?

I'm using automapper to map collections of incoming DTOs objects and save it all at once using Entity Framework. Everything works perfectly fine till I came across part of the database where we have circular references. It looks like automapper doesn't care about the object reference and instaed of mapping/creating new instance per each object, it creates multiple instance of mapped object when it's shared across multiple other objects.

Here is an example with what I would expect to happen with mapping:

I would expect to have only one 'GrandChild' object shared across two 'Child' objects of different types

and here is an example of what is actually happening:

After mapping I actually have two 'GrandChild' objects shared each by 'Child' object.

Maybe I'm using automapper in a wrong way, or perhaps any of you know a solution for that kind of scenario. We are already using automapper across the project and it's the first time we came across that issue and it would be really terrible to drop the whole concept and do everything manually.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source