title: Update non-scalar entities in Entity Framework v4
body: <p>Currently I am updating the scalar properties of the candidate object like so:</p>
  
  <pre><code>public Candidate EditCandidate(Candidate candidateToEdit)
      {
              _entities.Candidates.Attach(new Candidate { ID = candidateToEdit.ID });
              _entities.Candidates.ApplyCurrentValues(candidateToEdit);
  
              //update candidate.contact here somehow
  
              _entities.SaveChanges();
  
              return candidateToEdit;
      }
  </code></pre>
  
  <p>This only updates the Candidate scalars, since that's what ApplyCurrentValues does. I also need to update the candidate.contact object as well, currently it seems like the only option is to get the current candidate in the database via the candidateToEdit ID, grab the contact ID and updated it that way, but I'm not sure what the "best" way to do this is. candidateToEdit.contact has the values but not the ID since it doesn't get bound in my view. Do I change to the contact context and do that exactly the same way I updated the candidate?</p>
  
  <p>Update: Solution</p>
  
  <p>Based on <a href="https://stackoverflow.com/questions/3721755/update-non-scalar-entities-in-entity-framework-v4#3727273">Dan's answer</a> below.            </p>
  
  <pre><code>_entities.Candidates.Attach(candidateToEdit);
  _entities.ObjectStateManager.ChangeObjectState(candidateToEdit, EntityState.Modified);
  _entities.ObjectStateManager.ChangeObjectState(candidateToEdit.contact, EntityState.Modified);
  _entities.SaveChanges();
  </code></pre>