Exemplo n.º 1
0
        private void PerformUpdateInTransaction(IUpdate update)
        {
            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    _logger.LogInformation($"===== Performing update: {update} =====");
                    _logger.LogInformation($"Before Schema Change: {update}");
                    update.BeforeSchemaChange();
                    _logger.LogInformation($"Finished Before Schema Change: {update}");

                    _logger.LogInformation($"Schema Change: {update}");
                    update.SchemaChange(_context.Database);
                    _logger.LogInformation($"Finished Schema Change: {update}");

                    _logger.LogInformation($"After Schema Change: {update}");
                    update.AfterSchemaChange();
                    _logger.LogInformation($"Finished After Schema Change: {update}");
                    _logger.LogInformation($"===== Finished update: {update} =====");

                    dbContextTransaction.Commit();
                }
                catch (Exception e)
                {
                    _logger.LogError($"Release update failed. {e}");
                    dbContextTransaction.Rollback();
                    throw e;
                }
            }
        }