title: AutoMapper - Map List to HashSet
body: <p>I want to map my DTO to an entity. The only difference between the two is my dto's use List as collection type and the entities use HashSet. How can I configure Automapper to automatically map to a HashSet when it encounters an ICollection? Currently it just replaces the hashset in the entity with a List.</p>
  
  <p>Example classes and mapping:</p>
  
  <pre><code>cfg.CreateMap&lt;MachineDto, Machine&gt;(MemberList.Source)
  cfg.CreateMap&lt;Machine, MachineDto&gt;(MemberList.Destination)
  
  public class Machine
  {
      public Machine()
      {
          Segment = new HashSet&lt;Segment&gt;();
      }
  
      public long ID { get; set; }    
      public string Name { get; set; }            
      public ICollection&lt;Segment&gt; Segment { get; set; }
  }
  
  
  public class Segment
  {
      public Segment()
      {        
  
      }
  
      public long ID { get; set; }
      public long MachineID { get; set; }
      public string Serial { get; set; }
  }
  
  
  public class MachineDto
  {
      public MachineDto()
      {
          Segment = new List&lt;SegmentDto&gt;();
      }
  
      public long ID { get; set; }    
      public string Name { get; set; }            
      public ICollection&lt;SegmentDto&gt; Segment { get; set; }
  }
  
  
  public class SegmentDto
  {
      public SegmentDto()
      {        
  
      }
  
      public long ID { get; set; }
      public string Serial { get; set; }
  }
  </code></pre>