title: How do I use AutoMapper to map multiple subclasses into one class?
body: <p>Let's assume I have three classes that are subclasses of a base class:</p>
  
  <pre><code>public class BaseClass
  {
      public string BaseName { get; set; }
  }
  
  public class Subclass1 : BaseClass
  {
      public string SubName1 { get; set; }
  }
  
  public class Subclass2 : BaseClass
  {
      public string SubName2 { get; set; }
  }
  
  public class Subclass3 : BaseClass
  {
      public string SubName3 { get; set; }
  }
  </code></pre>
  
  <p>I would like to map these to a ViewModel class that looks like this:</p>
  
  <pre><code>public class ViewModel
  {
      public string BaseName { get; set; }
      public string SubName1 { get; set; }
      public string SubName2 { get; set; }
      public string SubName3 { get; set; }
  }
  </code></pre>
  
  <p><code>ViewModel</code> simply combines the properties on all of the subclasses and flattens it. I tried to configure the mapping like so:</p>
  
  <pre><code>AutoMapper.CreateMap&lt;BaseClass, ViewModel&gt;();
  </code></pre>
  
  <p>Then I tried grabbing data from my database like so:</p>
  
  <pre><code>var items = Repo.GetAll&lt;BaseClass&gt;();
  AutoMapper.Map(items, new List&lt;ViewModel&gt;());
  </code></pre>
  
  <p>However, what ends up happening is that only the <code>BaseName</code> property will be populated in the <code>ViewModel</code>. How would I configure AutoMapper so that it will map the properties in the subclasses as well?</p>