title: AutoMapper and interface typed collections
body: <p>I'm new to AutoMapper. Sorry if this is too simple.</p>
  
  <p>This is my sample domain:</p>
  
  <p><strong>I have a Basket. It contains a list of Food.
  Food is either Banana or Pickle.</strong></p>
  
  <p>I have DTOs that mirror each class in the domain. The goal: from a BasketDto, map it and its contents to a Basket.</p>
  
  <p>This is code that fails. After the last line I have a Basket, but it's filled with DTOs instead of regular entities :(</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Mapper.CreateMap&lt;BasketDto, Basket&gt;();
          Mapper.CreateMap&lt;PickleDto, Pickle&gt;();
          Mapper.CreateMap&lt;BananaDto, Banana&gt;();
  
          var dto = new BasketDto
                    {
                        Food = new List&lt;IFood&gt;
                               {
                                   new PickleDto { Name = "BigPickle" },
                                   new BananaDto { Name = "SmallBanana" },
                               }
                    };
  
          var basketFromDto = Mapper.Map&lt;Basket&gt;(dto);
      }
  }
  
  // Domain classes and interfaces --------------
  
  interface IFood
  {
      string Name { get; set; }
  }
  
  class Banana : IFood
  {
      public string Name { get; set; }
  }
  
  class Pickle : IFood
  {
      public string Name { get; set; }
  }
  
  class Basket
  {
      public IList&lt;IFood&gt; Food { get; set; }
  }
  
  // DTOs -------------
  
  class BasketDto
  {
      public IList&lt;IFood&gt; Food { get; set; }
  }
  
  class PickleDto : IFood
  {
      public string Name { get; set; }
  }
  
  class BananaDto : IFood
  {
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>What should I do to Map also the Children using Food as a IList? Mappin interfaces and hierarchies is really complex!</p>
  
  <p>Thanks a lot.</p>