/// <exception cref="OperationFailedException" /> static void DoDestroyStructure(bool inTransaction) { HConsole.PrintOperation("Уничтожение структуры данных"); QueryTextBuilder.Clear(); AppendQueryLine("BEGIN TRY"); ComposeDropTablesScript(); AppendQueryLine("END TRY"); AppendQueryLine("BEGIN CATCH"); AppendQueryLine("THROW"); AppendQueryLine("END CATCH"); try { using (var db = new DBC(false)) { if (inTransaction) { db.Database.BeginTransaction(); } db.Database.ExecuteSqlCommand(QueryTextBuilder.ToString()); if (inTransaction) { db.Database.CommitTransaction(); } } } catch (Exception e) { throw new OperationFailedException(e.Message); } }
/// <exception cref="OperationFailedException" /> static void DoDeleteData(bool inTransaction) { HConsole.PrintOperation("Удаление данных (очистка таблиц)"); QueryTextBuilder.Clear(); AppendQueryLine("BEGIN TRY"); ComposeDeleteTablesScript(); AppendQueryLine("END TRY"); AppendQueryLine("BEGIN CATCH"); AppendQueryLine("THROW"); AppendQueryLine("END CATCH"); try { using (var db = new DBC(false)) { if (inTransaction) { db.Database.BeginTransaction(); } db.Database.ExecuteSqlCommand(QueryTextBuilder.ToString()); if (inTransaction) { db.Database.CommitTransaction(); } } } catch (Exception e) { throw new OperationFailedException(e.Message); } }
/// <exception cref="OperationFailedException" /> static void DoFillTest(bool withCleanup) { try { using (var db = new DBC(false)) { db.Database.BeginTransaction(); if (withCleanup) { HConsole.PrintOperation("Предварительная очистка всех таблиц"); QueryTextBuilder.Clear(); AppendQueryLine("BEGIN TRY"); ComposeDeleteTablesScript(); AppendQueryLine("END TRY"); AppendQueryLine("BEGIN CATCH"); AppendQueryLine("THROW"); AppendQueryLine("END CATCH"); db.Database.ExecuteSqlCommand(QueryTextBuilder.ToString()); } HConsole.PrintOperation("Добавление тестовых данных (наполнение таблиц)"); FillTablesWithTest(db); db.SaveChanges(); db.Database.CommitTransaction(); } } catch (Exception e) { throw new OperationFailedException(e.Message); } }
/// <exception cref="OperationFailedException" /> static void DoCreateStructure() { HConsole.PrintOperation("Создание структуры данных (\"Database.EnsureCreated\")"); try { using (var db = new DBC(true)) {} } catch (Exception e) { throw new OperationFailedException(e.Message); } }