title: How to rollback a transaction in Date Entity Framework
body: <p>I am trying to use the Data Entity Framework to create my Data Access Layer.  In the work I have done up to now I have used ADO.Net.  I am trying to get my head around how transactions work in EF. I ave read loads but its all confussed me even more than I was before!!  I would usually do somethink like (simplified for example):</p>
  
  <pre><code>using (SqlConnection conn = new SqlConnection(_connString))
  {
      using (SqlTransaction trans = conn.BeginTransaction())
      {
          try
          {
              using (SqlCommand cmd = new SqlCommand("usp_CreateNewInvoice", conn))
              {
                  cmd.Transaction = trans;
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Parameters.Add(new SqlParameter("@InvoiceName", Invoice.invoicename));
                   cmd.Parameters.Add(new SqlParameter("@InvoiceAddess", Invoice.invoiceaddress));
                   _invoiceid = Convert.ToInt32(cmd.ExecuteScalar());
              }
              foreach (InvoiceLine inLine in Invoice.Lines)
              {
                  using (SqlCommand cmd = new SqlCommand("usp_InsertInvoiceLines", conn))
                  {
                      cmd.Transaction = trans;
                      cmd.CommandType = CommandType.StoredProcedure;
                      cmd.Parameters.Add(new SqlParameter("@InvNo", _invoiceid));
                      cmd.Parameters.Add(new SqlParameter("@InvLineQty", inLine.lineqty));
                      cmd.Parameters.Add(new SqlParameter("@InvLineGrossPrice", inLine.linegrossprice));
                      cmd.ExecuteNonQuery();
                  }
              }
              trans.Commit();
          }
          catch (SqlException sqlError)
          {
              trans.Rollback();
          }
      }
  }
  </code></pre>
  
  <p>Now I want to do the same in EF:</p>
  
  <pre><code>        using (TransactionScope scope = new TransactionScope())
          {
              try
              {
                  var DbContext = new CCTStoreEntities();
  
                  CCTInvoice invHead = new CCTInvoice();
                  invHead.Name = Invoice.invoicename;
                  invHead.Address = Invoice.invoiceaddress;
  
                  DbContext.CCTInvoices.Add(invHead);
                  DbContext.SaveChanges(false);
                  _iid = invHead.InvoiceId;
  
                  foreach (InvoiceLine inLine in Invoice.Lines)
                  {
                      CCTInvoiceLine invLine = new CCTInvoiceLine();
                      invLine.InvoiceNo = _iid;
                      invLine.Quantity = inLine.lineqty;
                      invLine.GrossPrice = inLine.linegrossprice;
                      DbContext.CCTInvoiceLines.Add(invHead);
                      DbContext.SaveChanges(false);
                  }
  
                  DbContext.SaveChanges();
                  scope.Complete();
  
              }
              catch
              {
                  //Something went wrong
                  //Rollback!
              }
          }
  </code></pre>
  
  <p>From what I read <code>SaveChanges(false)</code> means the changes being made will continue to be tracked. But how do I rollback the transaction if something goes wrong?</p>