title: AutoMapper many to many relationship into collection
body: <p>I'm trying to map entities into a collection through a many to many table using AutoMapper.  </p>
  
  <p>My domain model (Entity Framework) looks like this:</p>
  
  <pre><code>public class User
  {
      public int UserID { get; set; }
      public string Name { get; set; }        
      public IList&lt;UserCompany&gt; UserCompanies { get; set; }
  }
  
  public class Company
  {
      public int CompanyID { get; set; }
      public string Name { get; set; }
  }
  
  public class UserCompany
  {
      public int UserCompanyID { get; set; }
      public int UserID { get; set; }
      public int CompanyID { get; set; }
  }
  </code></pre>
  
  <p>I'm trying to map to a class that looks like this:</p>
  
  <pre><code>public class CompanyDTO
  {
      public int CompanyID { get; set; }
      public string Name { get; set; }
  }
  
  public class UserDTO
  {
      public int UserID { get; set; }
      public string Name { get; set; }
      public IList&lt;CompanyDTO&gt; Companies { get; set; }
  }
  </code></pre>
  
  <p>My current mapping configuration looks like this:</p>
  
  <pre><code>Mapper.CreateMap&lt;Company, CompanyDTO&gt;(); //works no problem
  
  Mapper.CreateMap&lt;User, UserDTO&gt;()
      .ForMember( dto =&gt; dto.Companies,
      opt =&gt; opt.MapFrom(x =&gt; Mapper.Map&lt;IList&lt;Company&gt;, IList&lt;CompanyDTO&gt;&gt;(x.UserCompanies.Select( y =&gt; y.Company ).ToList())));
  </code></pre>
  
  <p>Asserting that the configuration is valid returns true, but when I try to actually map a User to a UserDTO, I get: Signature of the body and declaration in a method implementation do not match.</p>
  
  <p>If I use AfterMap and manually move over each Company into the Companies list, it will work, but it seems like I should be able to handle this within create map.</p>
  
  <p>In my query to get a single user from the DB I am including the UserCompany.Company navigation property and I can quickwatch and see that there is being returned.</p>