title: AutoMapper With Generic Type Inheritance
body: <p>I'm trying to map CustomerDTO with my domain entity ICustomer with AutoMapper. Everything works fine for first inheritance level but not for the others.</p>
  
  <p>I'm using Interfaces for my domain model since concrete types are injected by StructureMap from my LinqToSql Database Infrastructure layer.</p>
  
  <pre><code>public interface IBaseEntity&lt;TPk&gt;
  {
      TPk Id { get; }
  }
  
  public interface ICustomer : IBaseEntity&lt;int&gt;
  {
      string Email { get; set; }
  }
  
  [DataContract]
  public class CustomerDTO
  {
      [DataMember]
      public int Id { get; set; }
  
      [DataMember]
      public string Email { get; set; }
  }
  </code></pre>
  
  <p>Now the AutoMapper mapping</p>
  
  <pre><code>Mapper.CreateMap&lt;CustomerDTO, ICustomer&gt;();
  
  Mapper.CreateMap&lt;ICustomer, CustomerDTO&gt;();
  
  Mapper.AssertConfigurationIsValid();
  </code></pre>
  
  <p>Now where i'm using the mapping</p>
  
  <pre><code>    public CreateCustomerServiceResult CreateCustomer(CustomerDTO customer)
      {
          var result = new CreateCustomerServiceResult();
          try
          {
              var originalMapped = Mapper.DynamicMap&lt;CustomerDTO, ICustomer&gt;(customer);
  
              var newCustomer = _customerService.CreateCustomer(originalMapped);
  
              var newMapped = Mapper.DynamicMap&lt;ICustomer, CustomerDTO&gt;(newCustomer);
  
              result.Customer = newMapped;
          }
          catch (Exception ex)
          {
  
          }
          return result;
      }
  </code></pre>
  
  <p>I've got a <strong>Dictionnary missing Key Exception</strong> on the "Id" property ...</p>