private void CreateFromSQL() { try { var connectionType = executeSQLDesigner.ResolvedConnectionType; string connectionString = executeSQLDesigner.ResolvedConnectionString; DataTable schemaTable = DatabaseHelpers.RetrieveSchema(connectionType, connectionString, SqlStringHandler.GetSqlStringHandler(this.executeSQLDesigner.ResolvedSqlStatementValue ?? string.Empty).GetExecutableDesignTimeSql()); var newResults = new List <ResultFieldModel>(); foreach (DataColumn dataColumn in schemaTable.Columns) { var oldModel = ResultFields.FirstOrDefault(x => x.ColumnName == dataColumn.ColumnName); if (oldModel != null) { newResults.Add(oldModel); continue; } ResultFieldModel newModel = new ResultFieldModel(this); newModel.IsDefault = false; newModel.ColumnName = dataColumn.ColumnName; newModel.Name = DatabaseHelpers.GetValidName(dataColumn.ColumnName); newModel.SetTypeReferenceValues(dataColumn.DataType); newModel.NameChanged += ModelNameChanged; newModel.ColumnNameChanged += ModelColumnNameChanged; newResults.Add(newModel); } ResultFields.Where(x => !newResults.Contains(x)).ToList().ForEach(x => { x.NameChanged -= ModelNameChanged; x.ColumnNameChanged -= ModelColumnNameChanged; }); ResultFields.Clear(); newResults.ForEach(x => ResultFields.Add(x)); AddDefaultChild(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }