title: Polymorphism with AutoMapper
body: <p>I have these business classes:</p>
  
  <pre><code>class BaseNode
      {
          public string name;        
      }
  
      class CompositeNode : BaseNode
      {
          public List&lt;BaseNode&gt; childs = new List&lt;BaseNode&gt;();
      }   
  </code></pre>
  
  <p>And this flat dto:</p>
  
  <pre><code>class NodeDto
      {
          public string name;
          public List&lt;NodeDto&gt; childs;
      }
  </code></pre>
  
  <p>(note how all derived types are represented by one  dto class)</p>
  
  <p>I use <a href="http://automapper.codeplex.com/" rel="nofollow noreferrer">auto mapper</a> to do a conversion:</p>
  
  <pre><code> Mapper.CreateMap&lt;BaseNode, NodeDto&gt;()
                  .Include&lt;CompositeNode, NodeDto&gt;()
                  .ForMember(s =&gt; s.childs, prop =&gt; prop.Ignore());
  
   Mapper.CreateMap&lt;CompositeNode, NodeDto&gt;();
  
   Mapper.AssertConfigurationIsValid();
  
   var root = new CompositeNode() { name = "root" };
   var child = new CompositeNode {name = "child"};
   var child2 = new CompositeNode { name = "child2" };            
   root.childs.Add(child);
   child.childs.Add(child2);
  
   var rootDto = Mapper.Map&lt;CompositeNode, NodeDto&gt;(root);
  </code></pre>
  
  <p>However the below is always null instead of having the child list:</p>
  
  <pre><code>rootDto.childs[0].childs
  </code></pre>
  
  <p>(i.e. only first level child is mapped correctly)</p>
  
  <p>If I remove the prop.Ignore part I get an assert error that the childs property is not mapped.</p>
  
  <p>What am I doing wrong?</p>