title: How to simply map an NHibernate ISet to IList using AutoMapper
body: <p>I'm trying to use AutoMapper to map from DTO's to my Domain.</p>
  
  <p>My DTO's might look like this:</p>
  
  <pre><code>public class MyDTO
  {
      public string Name { get; set; }
      public bool OtherProperty { get; set; }
  
      public ChildDTO[] Children { get; set;}
  }
  
  public class ChildDTO
  {
      public string OtherName { get; set; }
  }
  </code></pre>
  
  <p>My Domain objects like this:</p>
  
  <pre><code>public class MyDomain
  {
      public string Name { get; set; }
      public bool OtherProperty { get; set; }
      public ISet&lt;ChildDomain&gt; Children { get; set; }
  }
  
  public class ChildDomain
  {
      public string OtherName { get; set; }
  }
  </code></pre>
  
  <p>How would I setup AutoMapper to be able to map from these Array's to Set's. It seems like AutoMapper is taking the Array's and converting them into IList's then failing on conversion to ISet.</p>
  
  <p>Here's the exception</p>
  
  <pre><code>Unable to cast object of type 'System.Collections.Generic.List`1[DataTranser.ChildDTO]' to type 'Iesi.Collections.Generic.ISet`1[Domain.ChildDomain]'.
  </code></pre>
  
  <p>I'm hoping to find a simple generic way to do this so that I can minimize the infrastructure needed to map from DTO's to Domain. Any help is greatly appreciated.</p>
  
  <p><br /><br />
  <strong>UPDATE:</strong><br>
  So then how would I model MyDomain -> ChildDomain without ending up with an anemic domain model? I understand that without business logic in MyDomain or ChildDomain the domain model is currently anemic, but the goal was to add business logic in as we move forward. I just want to ensure that my View Model can be translated into the domain model and persisted.</p>
  
  <p>What would you suggest for this scenario, moving from a simple mapping between view and domain and later adding in business rules?</p>
  
  <p>Thanks again for your help.</p>