title: AutoMapper Master details mapping
body: <p>We are using AutoMapper for mapping business entities to data entities and vice versa. There are two classes, on which we would like to do updates on database.</p>
  
  <p><strong>ImportConfiguration</strong></p>
  
  <pre><code>[DataContract]
  public class ImportConfiguration : FileType
  {
      [DataMember]
      public Guid ImportConfigurationID { get; set; }
      [DataMember]
      public string FileMask { get; set; }
      [DataMember]
      public virtual List&lt;OrderConfiguration&gt; OrderConfigurations { get; set; }
  }
  </code></pre>
  
  <p><strong>OrderConfiguration</strong></p>
  
  <pre><code>[DataContract]
  public class OrderConfiguration 
  {
      [DataMember]
      public Guid OrderConfigurationID { get; set; }
      [DataMember]
      public Guid ImportConfigurationID { get; set; }
      [DataMember]
      public string OrderConfigData{ get; set; }
  }
  </code></pre>
  
  <p>Here is the mapping from Business entity to data entity for ImportConfiguration.</p>
  
  <pre><code> Mapper.CreateMap&lt;ImportConfiguration, Data.Entities.ImportConfigurations&gt;()
                .ForMember(d =&gt; d.OrderConfigurations, o =&gt; o.UseDestinationValue());
  </code></pre>
  
  <p>But when we are creating the mapping by</p>
  
  <pre><code>var newDbconfig = Mapper.Map&lt;ImportConfiguration, Data.Entities.ImportConfigurations&gt;(newBoConfig);
  </code></pre>
  
  <p>Following error message is raised :</p>
  
  <p><strong>Error Message :</strong></p>
  
  <p>The EntityCollection has already been initialized. The InitializeRelatedCollection method should only be called to initialize a new EntityCollection during deserialization of an object graph.</p>