title: Handling Referential Integrity Constraint Violations Correctly
body: <p>.Net4 Entity Framework, N-Tier (so objects are detatched)</p>
  
  <p>I have 2 objects generated Database first such that object1 has a Navigation Property (1 - 1) to object 2.</p>
  
  <p>I can successfully make changes to other properties of object 1, but when I try to change  object2 I get an error.</p>
  
  <p>My webpage has a drop down list of object2 names and indices.</p>
  
  <p>I have tried setting the object1.object2Id property and saving it and I get a referential Key error. (I can see that this may be because the object still holds the original object2).</p>
  
  <p>If however I load in the new object2 and attempt to update object1 I get the object could not be added or attached because its EntityReference has an Entity Key Property that does not match.</p>
  
  <p>So I seem to be going round in circles.</p>
  
  <p>So using Detached objects and Entity Framework, what is the correct way of updating a child object / foreign key?</p>