title: How to add/update many to many relations with one end of entity in EF core
body: <p>We have visited quite a few links on EF Core many to many update, yet could not figure a concrete answer to our question and clear our understanding.</p>
  
  <p>Scenario:
  We wish to add/update an entity and its related many to many relations in one go like (dbset.Add() or dbset.Update())</p>
  
  <p>We were trying the following and could only add/update the parent entity and not the many-to-many relation list. Can you help us know where we are wrong? and what can be done?</p>
  
  <p>Current Model Structure:</p>
  
  <pre><code>
          public class Teacher
      {
          [DatabaseGenerated(DatabaseGeneratedOption.Identity), Required]
          public long Id { get; set; }
          public string Name { get; set; }
          public List&lt;TeacherDuty&gt; TeacherDuties { get; set; }
      }
      public class Duty
      {
          [DatabaseGenerated(DatabaseGeneratedOption.Identity), Required]
          public long Id { get; set; }
          public string Description { get; set; }
          public List&lt;TeacherDuty&gt; TeacherDuties { get; set; }
      }
      public class TeacherDuty
      {
          public long TeacherId { get; set; }
          public Teacher Teacher { get; set; }
  
          public long DutyId { get; set; }
          public Duty Duty { get; set; }
      }
  
  </code></pre>
  
  <p>And we are trying to add/update using following methods:</p>
  
  <pre><code>public async Task&lt;Teacher&gt; AddTeacher(Teacher pTeacher)
  {
      try
      {
          return await _teacher.AddAsync(pTeacher);
      }
      catch (Exception ex) { throw ex; }
  }
  
  public async Task&lt;Teacher&gt; UpdateTeacher(Teacher pTeacher)
  {
      try
      {
          return await _teacher.Update(pTeacher);
      }
      catch (Exception ex) { throw ex; }
  }
  </code></pre>
  
  <p>Kindly point us to our misinterpretation of concept and solution if possible.
  Thanks.</p>