title: Entity Framework 6 multiple nested master-detail insert
body: <p>I have this tables scenario</p>
  
  <p><a href="http://i.stack.imgur.com/pTfDl.png" rel="nofollow">model</a></p>
  
  <p>So as you can see there are a multiple nested master-detail table and I have a requeriment where I have to insert at one time the first three entities, I'm using Entity Framework 6, Database First. (mvc Web api2). I managed to do first two entities at this way: </p>
  
  <pre><code>    Entity1 entity1 = new Entity1()
      {
         Field = "a field"
      };
  
      entity1.Entity2.Add(new Entity2() 
      {
         Field = "another field"
  
      });
  </code></pre>
  
  <p>//*******************************<br>
  //And the save is:  </p>
  
  <pre><code> using (var context = new backendEntities())
   {
      context.Entity1.Add(entity1);
      context.SaveChanges();
   }
  </code></pre>
  
  <p>And saves ok for the first two entities, but I'm not able or don't find a way for adding the next entity (Entity3). All the primary key are Identity autonumerics. How could I save these three entities at one time?. Thanks guys for your help.</p>