title: EntityFramework adding new object to nested object collection
body: <p>This question is a continuation of:</p>
  
  <p><a href="https://stackoverflow.com/q/13867609/1268570">EntityFramework adding new object to a collection</a></p>
  
  <p>Now I understand that when using <code>DbSet</code> EF won't load the entire collection into memory</p>
  
  <p>But what if I have something like the following code:</p>
  
  <pre><code>public class User
  {
      public int UserID { get; set; }
      public string UserName { get; set; }
      public ICollection&lt;Role&gt; Roles { get; set; }
  }
  
  public class Role
  {
      public int RoleID { get; set; }
      public string RoleName { get; set; }
      public User User { get; set; }
  }
  
  public class MyContext : DbContext
  {
      public DbSet&lt;User&gt; Users { get; set; }
      public DbSet&lt;Role&gt; Roles { get; set; }
  }
  
  public class SomeClass
  {
      public void AssignRoleToUser(int userID, Role role)
      {
          var ctx = new MyContext();
          var user = ctx.Users.First(x =&gt; x.UserID.Equals(userID));
  
          user.Roles.Add(role);
  
          ctx.SaveChanges();
      }
  }
  </code></pre>
  
  <p>In this case, I'm not using the <code>DbSet</code> object to add a new object to the <em>Role</em> collection, instead, I'm adding a new role to a specific user using an <code>ICollection</code> collection</p>
  
  <p>So what happens in this case?</p>
  
  <p>Does EntityFramewrk have to load into memory all the user's roles in order to perform the insert?</p>