title: saving data in multiple tables in one transaction using entity framework
body: <p>How can I save data into multiple tables in one transaction using entity framework?</p>
  
  <p>I have multiple void methods where I populate the context, but I want to save it in one transaction rather than saving it multiple times. What is the best way of doing this?</p>
  
  <pre><code>namespace DataAccess.Services
  {
      public class Submissions
      {
          DataContext Context;
  
          public Submissions()
          {
              Context = new DataContext();
          }
  
          public void InsertAllData()
          {
               //Save all data at once for all below contexts
               //DataContext.SaveChanges();  
          }
  
          void InsertObject1(int Object1Id )
          {
                 var obj1 = new DataAccess.Entity.Object1();
  
                  obj1.Field1 = ....
                  obj1.Field2 = ....
                  .....
  
                  DataContext.Objects.Add(obj1);
          }
  
          void InsertObject2(int Object2Id )
          {
                 var obj2 = new DataAccess.Entity.Object2();
  
                  obj2.Field1 = ....
                  obj2.Field2 = ....
                  .....
  
                  DataContext.Objects.Add(obj2);
          }
  
          void InsertObject3(int Object3Id )
          {
                 var obj3 = new DataAccess.Entity.Object3();
  
                  obj3.Field1 = ....
                  obj3.Field2 = ....
                  .....
  
                  DataContext.Objects.Add(obj3);
          }
  
      }
  }
  </code></pre>