title: Entity framework 6 transaction
body: <p>I need to insert  new rows in two of my tables first table's auto generated id field is one of the field of second table .currently I'm using transaction  for inserting data. My current code is given below</p>
  
  <pre><code>        using (var context = new ApplicationDatabaseEntities())
          {
              using (var transaction = context.Database.BeginTransaction())
              {
                  try
                  {
                     foreach (var item in itemList)
                     {
                      context.MyFirstEntity.Add(item);
                      context.SaveChanges();
  
                      mySecondEntity.MyFirstEntityId = item.Id;
                      context.MySecondEntity.Add(mySecondEntity.MyFirstEntityId );
                      context.SaveChanges();
  
                     }
                    transaction.Commit();
                  }
                  catch (Exception ex)
                  {
                      transaction.Rollback();
                      Console.WriteLine(ex);
  
                  }
              }
          }
  </code></pre>
  
  <p>The above code is working fine .my question is, is this the correct way? I mean if I have 1000 or 2000 items for insertion does my current code affect the performance </p>