Ejemplo n.º 1
0
        /// <summary>
        /// Creates a transaction and exectures the passed code then commits or rolls back automatically
        /// </summary>
        /// <param name="db"></param>
        /// <param name="cb">The code to execute</param>
        public static async Task Transaction(this System.Data.Entity.Database db, Func <Task> cb)
        {
            using (var tx = db.BeginTransaction())
            {
                try
                {
                    await cb();

                    tx.Commit();
                }
                catch (Exception)
                {
                    tx.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
 //
 // Summary:
 //     Begins a transaction on the underlying store connection
 //
 // Returns:
 //     a System.Data.Entity.DbContextTransaction object wrapping access to the underlying
 //     store's transaction object
 public IDbContextTransactionBase BeginTransaction()
 {
     return(new DbContextTransactionBase(_database.BeginTransaction()));
 }