title: Why is automapper making Entity Framework insert instead of update?
body: <p>I have a Customers table with a foreign reference to the Addresses table.  It appears that AutoMapper is doing something to make EF think that my Address reference is a new record rather than updating the existing record.</p>
  
  <p>This code updates the Address record correctly.  It does not add a new one:</p>
  
  <pre><code>using (CSIntUnitOfWork uow = new CSIntUnitOfWork())
  {
      CustomerRepository customerRepository = new CustomerRepository(uow, _resellerID);
  
      DataModels.Customer updateCustomer = customerRepository.GetByID(customer.CustomerID);
  
      updateCustomer.ResellerID = customer.ResellerID;
      updateCustomer.CustomerType = customer.CustomerType;
      updateCustomer.Password = customer.Password;
      updateCustomer.Comments = customer.Comments;
  
      updateCustomer.Address.ResellerID = customer.Address.ResellerID;
      updateCustomer.Address.AddressCode = customer.Address.AddressCode;
      updateCustomer.Address.AddressType = customer.Address.AddressType;
      updateCustomer.Address.CompanyName = customer.Address.CompanyName;
      updateCustomer.Address.LastName = customer.Address.LastName;
      updateCustomer.Address.FirstName = customer.Address.FirstName;
  
      uow.SaveChanges();
  }
  </code></pre>
  
  <p>This code will always add a new Address record:</p>
  
  <pre><code>using (CSIntUnitOfWork uow = new CSIntUnitOfWork())
  {
      CustomerRepository customerRepository = new CustomerRepository(uow, _resellerID);
  
      DataModels.Customer updateCustomer = customerRepository.GetByID(customer.CustomerID);
  
      Mapper.CreateMap&lt;Customer, Customer&gt;()
          .ForMember(dest =&gt; dest.CustomerID, opt =&gt; opt.Ignore());
      Mapper.Map(customer, updateCustomer);
  
      Mapper.CreateMap&lt;Address, Address&gt;()
          .ForMember(dest =&gt; dest.ID, opt =&gt; opt.Ignore());
      Mapper.Map(customer.Address, updateCustomer.Address);
  
      uow.SaveChanges();
  }
  </code></pre>
  
  <p>Any ideas why this is happening?</p>