title: Update many-to-many relationship efficiently
body: <p>I've 2 model classes. </p>
  
  <pre><code>public class Candidate
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection&lt;Skill&gt; Skills { get; set; }
  }
  
  public class Skill
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection&lt;Candidate&gt; Candidates { get; set; }
  }
  </code></pre>
  
  <p>This creates me 3 tables.</p>
  
  <ul>
  <li>Candidates
  <ul>
  <li>Id  Name </li>
  <li>1   Tom </li>
  <li>2   John</li>
  </ul></li>
  </ul>
  
  <hr>
  
  <ul>
  <li>Skills
  <ul>
  <li>Id  Name</li>
  <li>1    C#</li>
  <li>2    MVC</li>
  <li>3    SQL</li>
  <li>4    nHibernate</li>
  <li>5    Java
  <hr></li>
  </ul></li>
  </ul>
  
  <p>I've made the association in the AUTOGENERATED table : </p>
  
  <ul>
  <li>CandidateSkills
  <ul>
  <li>CandidateId SkillId</li>
  <li>1             2</li>
  <li>1             3</li>
  </ul></li>
  </ul>
  
  <hr>
  
  <p>Now I've want to update the skills for <b> candidateId 1 i.e. Tom who wants to remove his SkillId : 2 i.e. MVC and add new SkillId : 4 &amp; 5 i.e. nHibernate &amp; Java respectively</b>.</p>
  
  <p>I get the set of <b> Ids </b> from the form i.e. <b> 3, 4 &amp; 5  &amp; and the candidate Id : 1 </b>, Since 2 is removed by the user. </p>
  
  <p>My API is like this :</p>
  
  <pre><code>public Candidate Add(int candidateId, int[] skillIds)
  {
      var model = dbContext.candidate.Find(candidateId);
  }
  </code></pre>
  
  <hr>
  
  <p>How do I update the candidate record in an efficient way, making the least database calls?</p>