title: automapper Many-to-Many relation mapping
body: <p>Let's say, in the BookDetails page (BookForDetailsDto) we also show the authors of that book (AuthorForListingDto). And moreover, I want to show this author list together with a little info (just the name and id) on the books (BookForAuthorListingDto) of each author.</p>
  
  <p>I have a simple many-to-many relation consisting of Book, Author and BookAuthor objects.</p>
  
  <pre><code>public class Book {        
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;BookAuthor&gt; Authors { get; set; }
  }
  
  public class Author {
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;BookAuthor&gt; Books { get; set; }
  }
  
  public class BookAuthor {
      public int BookId { get; set; }
      public Book Book { get; set; }
      public int AuthorId { get; set; }
      public Author Author { get; set; }
  }
  </code></pre>
  
  <p>And I have also 3 DTOs (where I am stoping an infinite loop):</p>
  
  <pre><code>public class BookForDetailsDto {
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;AuthorForListingDto&gt; Authors { get; set; }
  }
  
  public class AuthorForListingDto {
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;BookForAuthorListingDto&gt; Books { get; set; }
  }
  
  public class BookForAuthorListingDto {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>Having a configuration as the following:</p>
  
  <pre><code>var config = new MapperConfiguration(cfg =&gt; {
      cfg.CreateMap&lt;Book, BookForDetailsDto&gt;();
      cfg.CreateMap&lt;BookAuthor, AuthorForListingDto&gt;();
      cfg.CreateMap&lt;AuthorForListingDto, BookForAuthorListingDto&gt;();
  });
  </code></pre>
  
  <p>I'd like to perform a mapping from Book to BookForDetailsDto like this.</p>
  
  <pre><code>BookForDetailsDto BookDto = mapper.Map&lt;BookForDetailsDto&gt;(book);
  </code></pre>
  
  <p>But as a result, I get System.NullReferenceException. 
  It seems like, just in the first level of mapping, AutoMapper cannot get Author information from BookAuthor object. 
  I am searching for a configuration option but with no luck. I should say I am a newbie with automapper and if there is a simple solution I appreciate.</p>
  
  <p>Note: I saw a comment which goes like "it is not a good practice to have reference in one DTO to second DTO". But I cannot figure out how to do otherwise, because ,for example, for a clickable/navigatable child_object we need at least "a key and a display_name", so a child object of type List seems inevitable. </p>