title: AutoMapper flattening of nested mappings asks for a custom resolver
body: <p>I'm somewhat new to AutoMapper and wanted to map a POCO-ish object to a perhaps more complex DTO, the latter tries to be a representation of a <a href="https://developers.google.com/books/docs/v1/reference/volumes" rel="nofollow noreferrer">Google Books API's Volume</a> resource:</p>
  
  <p><strong>Book.cs</strong></p>
  
  <pre><code>public class Book
  {
      public string Isbn10 { get; set; }
      public string Isbn13 { get; set; }
      public string Title { get; set; }
      public string Author { get; set; }
      public string Publisher { get; set; }
      public DateTime Publication { get; set; }
      public int Pages { get; set; }
      public string Description { get; set; }
      public bool InStock { get; set; }
  }
  </code></pre>
  
  <p><strong>BookDto.cs</strong></p>
  
  <pre><code>public class BookDto
  {
      public string Kind { get; set; }
      public string Id { get; set; }
      public VolumeInfo VolumeInfo { get; set; }
  }
  
  public class VolumeInfo
  {
      public string Title { get; set; }
      public List&lt;string&gt; Authors { get; set; }
      public string Publisher { get; set; }
      public string PublishedDate { get; set; }
      public string Description { get; set; }
      public int PageCount { get; set; }
      public List&lt;IndustryIdentifier&gt; IndustryIdentifiers { get; set; }
  }
  
  public class IndustryIdentifier
  {
      public string Type { get; set; }
      public string Identifier { get; set; }
  }
  </code></pre>
  
  <p>So according to the <a href="https://github.com/AutoMapper/AutoMapper/wiki/Nested-mappings" rel="nofollow noreferrer">documentation</a> <em>we could simply flatten</em> the nested type:</p>
  
  <p><strong>AutoMapperConfigurator.cs</strong></p>
  
  <pre><code>public static class AutoMapperConfigurator
  {
      public static void Configure()
      {
          Mapper.CreateMap&lt;Book, BookDto&gt;()
              .ForMember(dto =&gt; dto.Id, options =&gt; options.Ignore())
              .ForMember(dto =&gt; dto.Kind, options =&gt; options.Ignore())
              .ForMember(dto =&gt; dto.VolumeInfo.Title, options =&gt; options.MapFrom(book =&gt; book.Title))
              .ForMember(dto =&gt; dto.VolumeInfo.Authors, options =&gt; options.MapFrom(book =&gt; book.Author.ToArray()))
              .ForMember(dto =&gt; dto.VolumeInfo.Publisher, options =&gt; options.MapFrom(book =&gt; book.Publisher))
              .ForMember(dto =&gt; dto.VolumeInfo.PublishedDate, options =&gt; options.MapFrom(book =&gt; book.Publication))
              .ForMember(dto =&gt; dto.VolumeInfo.Description, options =&gt; options.MapFrom(book =&gt; book.Description))
              .ForMember(dto =&gt; dto.VolumeInfo.PageCount, options =&gt; options.MapFrom(book =&gt; book.Pages))
              ;
      }
  }
  </code></pre>
  
  <p>But unfortunately when running the <code>Mapper.AssertConfigurationIsValid()</code> Test I'm getting the following error:</p>
  
  <blockquote>
    <p>System.ArgumentException : Expression 'dto => dto.VolumeInfo.Title'
    must resolve to top-level member and not any child object's
    properties. Use a custom resolver on the child type or the AfterMap
    option instead. Parameter name: lambdaExpression</p>
  </blockquote>
  
  <p>So now following that advice trying with AfterMap:</p>
  
  <pre><code>public static class AutoMapperConfigurator
  {
      public static void Configure()
      {
          Mapper.CreateMap&lt;Book, BookDto&gt;()
              .ForMember(dto =&gt; dto.Id, options =&gt; options.Ignore())
              .ForMember(dto =&gt; dto.Kind, options =&gt; options.Ignore())
              .AfterMap((book, bookDto) =&gt; bookDto.VolumeInfo = new VolumeInfo 
                  { 
                      Title = book.Title,
                      Authors = new List&lt;string&gt;(){ book.Author },
                      Publisher = book.Publisher,
                      PublishedDate = book.Publication.ToShortDateString(),
                      Description = book.Description,
                      PageCount = book.Pages
                  });
      }
  }
  </code></pre>
  
  <p>When running the test again I'm now getting this message:</p>
  
  <blockquote>
    <p>Unmapped members were found. Review the types and members below. Add a
    custom mapping expression, ignore, add a custom resolver,  or modify
    the source/destination type Book -> BookDto (Destination member list)
    Dotnet.Samples.AutoMapper.Book -> Dotnet.Samples.AutoMapper.BookDto
    (Destination member list) VolumeInfo</p>
  </blockquote>
  
  <p>Should I create additional mappings between the nested classes? Any guidance will be sincerely appreciated, thanks much in advance.</p>