title: EF Insert entity with large number of new child entities
body: <p>I've seen a number of "Bulk Insert in EF" questions however all of these deal with a usecase where a user is trying to insert a large array of items.</p>
  
  <p>I've a situation where I have a new Parent entity with ~1500 new related entities attached to it. Both the parent and the child entities are mapped to their own tables in EF.</p>
  
  <p>At the moment I'm using something like:</p>
  
  <pre><code>//p is already created and contains all the new child items    
  public void SaveBigThing(Parent p){
    if(p.Id == 0){
      // we've got a new object to add
      db.BigObjects.Add(p);
    }
    db.SaveChanges();
  }
  </code></pre>
  
  <p>Entity Framework at the moment creates an individual insert statement for each and every child item. Which takes 50 seconds or so. I want to be able to use <code>db.ChildEntity.AddRange(items)</code> But I'm unsure if there's a better way than to use 2 separate operations. First create the parent to get it's Id then a <code>AddRange</code> for all the child items?</p>