title: Entity framework performing an Insert, when it should be doing an Update
body: <p>I am having a real issue with the EF v1. I have quite a big EDMX with maybe 50 entities mapped, but this one entity is causing me grief.</p>
  
  <p>The entity has mappings to other entities which in effect are reference tables, but for some reason it is trying to do an insert and not just update itself.</p>
  
  <p>Here is a fragment of my code:</p>
  
  <pre><code>using (var context = new someEntities()) {
      var studentCourseJoin =
          context.StudentCourseJoinSet.Where(o =&gt; o.Code == scjCode).First();
  
      studentCourseJoin.EntryStatus = new EntryStatus { Code = viewModel.StudentDetails.EntryStatusCode };
      studentCourseJoin.ParentalInHigherEducation = new ParentalInHigherEducation { Code = viewModel.StudentDetails.ParentalInHigherEducationCode };
      studentCourseJoin.School = new School { Code = viewModel.StudentDetails.SchoolCode };
  
      studentCourseJoin.Institution = new Institution { Code = viewModel.StudentDetails.InstitutionCode };
  
      studentCourseJoin.LastSchoolEndYear = viewModel.StudentDetails.LastSchoolEndYear;
      studentCourseJoin.LastInstitutionEndYear = viewModel.StudentDetails.LastInstitutionEndYear;
  
      // Blows up here trying to do an insert on the studentCourseJoin.Institution.
      // But if I removed this one, then it will blow up on another one.
      context.SaveChanges(true);
  }
  </code></pre>
  
  <p>If anyone has ANY ideas please, they would help a lot.</p>