private static IEnumerable <string> BuildCommands(ISource DesiredStructure, ISource CurrentStructure) { var Commands = new List <string>(); DesiredStructure = DesiredStructure.Check(new Database("")); if (CurrentStructure == null) { Commands.Add(string.Format(CultureInfo.CurrentCulture, "EXEC dbo.sp_executesql @statement = N'CREATE DATABASE {0}'", DesiredStructure.Name)); } CurrentStructure = CurrentStructure.Check(new Database(DesiredStructure.Name)); foreach (Table Table in DesiredStructure.Tables) { ITable CurrentTable = CurrentStructure[Table.Name]; Commands.Add((CurrentTable == null) ? GetTableCommand(Table) : GetAlterTableCommand(Table, CurrentTable)); } foreach (Table Table in DesiredStructure.Tables) { ITable CurrentTable = CurrentStructure[Table.Name]; Commands.Add((CurrentTable == null) ? GetForeignKeyCommand(Table) : GetForeignKeyCommand(Table, CurrentTable)); Commands.Add((CurrentTable == null) ? GetTriggerCommand(Table) : GetAlterTriggerCommand(Table, CurrentTable)); } foreach (Function Function in DesiredStructure.Functions) { var CurrentFunction = (Function)CurrentStructure.Functions.FirstOrDefault(x => x.Name == Function.Name); Commands.Add(CurrentFunction != null ? GetAlterFunctionCommand(Function, CurrentFunction) : GetFunctionCommand(Function)); } foreach (View View in DesiredStructure.Views) { var CurrentView = (View)CurrentStructure.Views.FirstOrDefault(x => x.Name == View.Name); Commands.Add(CurrentView != null ? GetAlterViewCommand(View, CurrentView) : GetViewCommand(View)); } foreach (StoredProcedure StoredProcedure in DesiredStructure.StoredProcedures) { var CurrentStoredProcedure = (StoredProcedure)CurrentStructure.StoredProcedures.FirstOrDefault(x => x.Name == StoredProcedure.Name); Commands.Add(CurrentStoredProcedure != null ? GetAlterStoredProcedure(StoredProcedure, CurrentStoredProcedure) : GetStoredProcedure(StoredProcedure)); } return(Commands); }
private static IEnumerable<string> BuildCommands(ISource DesiredStructure, ISource CurrentStructure) { var Commands = new List<string>(); DesiredStructure = DesiredStructure.Check(new Database("")); if (CurrentStructure == null) Commands.Add(string.Format(CultureInfo.CurrentCulture, "EXEC dbo.sp_executesql @statement = N'CREATE DATABASE {0}'", DesiredStructure.Name)); CurrentStructure = CurrentStructure.Check(new Database(DesiredStructure.Name)); foreach (Utilities.ORM.Manager.Schema.Default.Database.Table Table in DesiredStructure.Tables) { ITable CurrentTable = CurrentStructure[Table.Name]; Commands.Add((CurrentTable == null) ? GetTableCommand(Table) : GetAlterTableCommand(Table, CurrentTable)); } foreach (Utilities.ORM.Manager.Schema.Default.Database.Table Table in DesiredStructure.Tables) { ITable CurrentTable = CurrentStructure[Table.Name]; Commands.Add((CurrentTable == null) ? GetForeignKeyCommand(Table) : GetForeignKeyCommand(Table, CurrentTable)); Commands.Add((CurrentTable == null) ? GetTriggerCommand(Table) : GetAlterTriggerCommand(Table, CurrentTable)); } foreach (Function Function in DesiredStructure.Functions) { var CurrentFunction = (Function)CurrentStructure.Functions.FirstOrDefault(x => x.Name == Function.Name); Commands.Add(CurrentFunction != null ? GetAlterFunctionCommand(Function, CurrentFunction) : GetFunctionCommand(Function)); } foreach (View View in DesiredStructure.Views) { var CurrentView = (View)CurrentStructure.Views.FirstOrDefault(x => x.Name == View.Name); Commands.Add(CurrentView != null ? GetAlterViewCommand(View, CurrentView) : GetViewCommand(View)); } foreach (StoredProcedure StoredProcedure in DesiredStructure.StoredProcedures) { var CurrentStoredProcedure = (StoredProcedure)CurrentStructure.StoredProcedures.FirstOrDefault(x => x.Name == StoredProcedure.Name); Commands.Add(CurrentStoredProcedure != null ? GetAlterStoredProcedure(StoredProcedure, CurrentStoredProcedure) : GetStoredProcedure(StoredProcedure)); } return Commands; }