title: Delete/Update Many to Many Entity Framework. Cannot get it to work
body: <p>I m using EF4 and having problems with many to many update and delete of item.
  I am happy with the insert but update and delete cannot figure it out.</p>
  
  <p>Suppose I have 3 tables and 3 dto classes that matches</p>
  
  <ol>
  <li><p>ClassRoom    Table           </p>
  
  <pre><code>   ClassID-ClassName 
  </code></pre></li>
  <li><p>Student      Table     </p>
  
  <pre><code>   StudentID-StudentName
  </code></pre></li>
  <li><p>StudentClass Table       </p>
  
  <pre><code>   StudentID-ClassID
  
  
  ///Happy all works I am using existing students to populate the class. Fine.
  private void InsertClassRoom(ClassRoomDto classRoomDto)
  {
      using (var ctx = new TrainingContext())
      {
          //Convert dto to Entity
          var classRoomEntity = new ClassRoom { ClassID = classRoomDto.ClassId, ClassName = classRoomDto.ClassName };
          foreach (var studentInClass in classRoomDto.Students)
          {
              Student student = ctx.Students.Where(x =&gt; x.StudentID == studentInClass.StudentId).SingleOrDefault();
              classRoomEntity.Students.Add(student);
          }
          ctx.AddToClassRooms(classRoomEntity);
          ctx.SaveChanges();
      }
  }
  </code></pre></li>
  </ol>
  
  <p>But I have  2 scenarios that cannot figure out what to do.</p>
  
  <ol>
  <li>Update the classroom Name</li>
  <li>Add 1 student </li>
  <li>Update the name on 1 student</li>
  </ol>
  
  <p>Delete a student from class.<br>
  How do I do it?</p>
  
  <p>This is my attempt on update:</p>
  
  <pre><code>private void UpdateClassRoom(ClassRoomDto classRoomDto)
  {
      using (var ctx = new TrainingContext())
      {
          var classRoomEntity = new ClassRoom { ClassID = classRoomDto.ClassId, ClassName = classRoomDto.ClassName };
          foreach (var studentDto in classRoomDto.Students)
          {
              if (studentDto.StudentId == 0)
              {
                  //it's a new student add it to the classroom
                  Student student = new Student { StudentID = studentDto.StudentId, StudentName = studentDto.StudentName };
                  classRoomEntity.Students.Add(student);
              }
              else
              {
                  //Alter name of the student
                  Student student = ctx.Students.Where(x =&gt; x.StudentID == studentDto.StudentId).SingleOrDefault();
                  //update name
                  student.StudentName = studentDto.StudentName;
                  //? what do I do finish this attach or ???
             }
          }
          ctx.AddToClassRooms(classRoomEntity);
          ctx.SaveChanges();
      }
  }
  
  public void DeleteStudent(ClassRoomDto classRoomDto)
  {
      using (var ctx = new TrainingContext())
      {
          //lost on how to delete a student in  many to many 
      }
  }
  </code></pre>