title: Entity Framework (4.0) - Adding new records with Foreign Key
body: <p>We have a table "Issues" with a foreign fey to the "Contacts" table". Ideally when a new Issue is added the user should select the Contact from a drop down. However, in some cases the contact may not already exist, so the user can add minimal new contact details to get the issue into the database. (This is a Support Desk app, and speed is of the essence to the operators). The contact data is cleaned up at a later date.</p>
  
  <p>So in the code we detect a new contact and create a new one in the database using Entity Framework: <code>_context.AddToContacts(_contact);</code>. We then need to retrieve the new id for updating on the issue - so a read from the contacts table to get last record added.
  This works fine.</p>
  
  <p>Then we build the Issues record, including the new foreign key using <code>ContactsReference.EntityKey</code>.
  When we Save the Issue <code>SaveChanges</code> we get the Issue record okay (with the correct foreign key back to Contacts) but we get another Contacts record added to the database.</p>
  
  <p>Are we doing too much work here? Or should Entity Framework be able to handle both adds and manage the data link correctly between the tables?</p>