title: AutoMapper Take Properties from Child
body: <p>My model is similar to the following:</p>
  
  <pre><code>public class Source
  {
      public string Property1 { get; set; }
      public string Property2 { get; set; }
  }
  
  public class SourceContainer
  {
      public Source Source { get; set; }
      public string ExtraData { get; set; }
  }
  
  public class SourceViewModel
  {
      public string Property1 { get; set; }
      public string Property2 { get; set; }
      public string ExtraData { get; set; }
  }
  
  Mapper.CreateMap&lt;Source, SourceViewModel&gt;();
  </code></pre>
  
  <p>When I want to map from Source to SourceViewModel, everything is fine and I just don't have <code>ExtraData</code> populated. But I also want to map from a <code>SourceContainer</code> to <code>SourceViewModel</code>, preferably without specifying the mapping for each property.</p>
  
  <p>Is it possible to tell AutoMapper to import properties from a child property, Source, when doing the mapping? Something like:</p>
  
  <pre><code>Mapper.CreateMap&lt;SourceContainer, SourceViewModel&gt;()
      .UseMappingForProperty(x =&gt; x.Source);
  </code></pre>
  
  <p>Otherwise I can tell AutoMapper about each property on <code>SourceViewModel</code> separately and get it from the child Source, but I'm wondering if there's a more elegant approach.</p>