Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I also get the same issue. It doesn't happen when you map the same object twice - it happens when you have a tree heirarcy of objects, and the same value exists in two places of the tree (but with different child values) When mapping the second instance of the item - it uses the child values of the first instance, instead of re-evaluating what the child values should be.</p> <p>Here is my example:</p> <pre><code>class Tag { int Id {get; set;} string Name {get; set;} IEnumerable&lt;Tag&gt; ChildTags {get; set;} } public void Test() { var source = new List&lt;Tag&gt; { new Tag { Id = 1, Name = "Tag 1", ChildTags = new List&lt;Tag&gt; { new Tag { Id = 2, Name = "Tag 2", ChildTags = new List&lt;Tag&gt; { new Tag {Id = 3, Name = "Tag 3"}, new Tag {Id = 4, Name = "Tag 4"} } } } }, new Tag { Id = 1, Name = "Tag 1" }, new Tag { Id = 3, Name = "Tag 3", ChildTags = new List&lt;Tag&gt; { new Tag {Id = 4, Name = "Tag 4"} } } }; Mapper.CreateMap&lt;Tag, Tag&gt;() .ForMember(dest =&gt; dest.ChildTags, opt =&gt; opt.MapFrom(src =&gt; src.ChildTags)); var result = Mapper.Map&lt;IList&lt;Tag&gt;, IList&lt;Tag&gt;&gt;(tags); } </code></pre> <p>In the result </p> <ul> <li><p>the first instance of Tag 1 (ie source[0]) and all of its children are perfect</p></li> <li><p>the second instance of Tag 1 (ie source[1]) has all the children of the first instance - it should not have any children</p></li> <li><p>the second instance of Tag 3 (ie source[2]) does not have any children - it should have Tag 4 as a child</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload