コード例 #1
0
 public async Task CommitAsync()
 {
     using (var _connection = new SqlConnection(_connectionString))
     {
         _connection.Open();
         var _transaction = _connection.BeginTransaction();
         try
         {
             foreach (var command in _dbContext.GetQueue())
             {
                 await command.ExecuteAsync(_transaction);
             }
             _transaction.Commit();
             _dbContext.ClearQueue();
             _connection.Close();
         }
         catch
         {
             _transaction.Rollback();
             throw;
         }
         finally
         {
             _dbContext.ClearQueue();
             _connection.Close();
             _transaction?.Dispose();
         }
     }
 }