title: Deleting a Many-to-Many Navigation Property
body: <p>I have three tables:-</p>
  
  <p>SecurityRole &amp; Groups &amp; SecurityRoleGroups. (securityrole can have many groups. and a group can have many securityroles)</p>
  
  <p>where the SecurityRoleGroup table is a many-to-many relation table, and Entity framework will not map this table . so i want to remove all the SecurityRoleGroup records that belong to certain SecurityRole. if i write something  as</p>
  
  <pre><code>SecurityRole securityrole = FindAllRole(id);
  
  tms.SecurityRoles.Remove(securityrole).Groups.Where(a=&gt; a.GroupID == group.GroupID)
  </code></pre>
  
  <p>will it remove only the needed records from the SecurityRoleGroup, ot it will also remove the related SecurityRole record ?</p>
  
  <p><strong>:::UPDATE:::</strong></p>
  
  <p>But what if I want to delete the Many-To-Many record only incase it is inside the currentGroups[c] array. can I write something as follow:-</p>
  
  <pre><code> if (group.GroupID == currentGroups[c])
                              {
  var securityrole = tms.SecurityRoles.Where(a =&gt; a.SecurityRoleID == id).Include(p =&gt; p.Groups).SingleOrDefault();
  
      (securityrole != null) {
  
      securityrole.Groups.Remove(group);
  
                                  }
                              }
  </code></pre>