title: Many-to-Many Inserts with Entity Framework
body: <p>Say I have two entities with about 20 properties per entity and a Many-to-Many relationship like so:</p>
  
  <pre><code>User (Id int,Name string, .......)
  Issue (Id int,Name string, .......)
  IssueAssignment (UserId,RoleId)
  </code></pre>
  
  <p>I want to create a new Issue and assign it to a number of existing Users. If I have code like so:</p>
  
  <pre><code>foreach(var userId in existingUserIds)
  {
     int id = userId
     var user = _db.Users.First(r =&gt; r.Id == id);        
     issue.AssignedUsers.add(user);     
  }
  
  _db.Users.AddObject(user);
  _db.SaveChanges();
  </code></pre>
  
  <p>I noticed it seems terrribly inefficient when I run it against my SQL Database. If I look at
  the SQL Profiler it's doing the following:</p>
  
  <ol>
  <li>SELECT TOP(1) * FROM User WHERE UserId = userId</li>
  <li>SELECT * FROM IssueAssignment ON User.Id = userId</li>
  <li>INSERT INTO User ....</li>
  <li>INSERT INTO IssueAssignment</li>
  </ol>
  
  <p>My questions are:<br>
  (a) why do (1) and (2) have to happen at all?<br>
  (b) Both (1) and (2) bring back all fields do I need to do a object projection to limit the
  fields, seems like unnecessary work too.  </p>
  
  <p>Thanks for the help</p>