Against my object context, I have the following call's There are methods in between these that populate my object's but I didn't want to clutter my example here.


Code:
_context.AttachTo("Cases", oCase); 
_context.ObjectStateManager.ChangeObjectState(oCase, EntityState.Added); 
 
_context.AttachTo("Policies", policy); 
_context.ObjectStateManager.ChangeObjectState(policy, EntityState.Added); 
 
_context.AttachTo("Addresses", address); 
_context.ObjectStateManager.ChangeObjectState(address, EntityState.Added); 
 
_context.AttachTo("Clients", client); 
_context.ObjectStateManager.ChangeObjectState(client, EntityState.Added); 
 
_context.SaveChanges(SaveOptions.None); 
 
_context.AttachTo("Policies", policy1); 
_context.ObjectStateManager.ChangeObjectState(policy1, EntityState.Added); 
 
_context.AttachTo("Addresses", address1); 
_context.ObjectStateManager.ChangeObjectState(address1, EntityState.Added); 
 
_context.AttachTo("Clients", client1); 
_context.ObjectStateManager.ChangeObjectState(client1, EntityState.Added);  
 _context.SaveChanges(SaveOptions.None);
Essentially this is the order above. The first _context.SaveChanges seems to work. If I step my code after this I can go tomy tables in the DB and see my records. When I hit the second SaveChanges, it fails saying their are duplicate keys in Address's, My Address table has a single int colums on the table that is the primary key. Checking this after the first save the ID = 1 as expected. The address1 object that gets attached for the second save has it's primarykey set to 2 and so I do not understand why it fails. any ideas anybody


.