private static bool ShouldTryAutoJoin(IQueryableColumn current, QueryTree queryTree) { if (!SchemaCompare.TablesAreSame(current.Table, queryTree.Table)) { foreach (JoinPredicate join in queryTree.Joins) { if (SchemaCompare.TablesAreSame(join.ToColumn.Table, current.Table)) { return(false); } } return(true); } return(false); }
public Database(IonStructure.Database database) { if (database == null) { throw new ArgumentNullException(nameof(database)); } Name = database.Name; CreateProject = database.CreateProject; DatabaseDependencies = GetDatabaseDependencies(database.Dependencies); FolderIncludePaths = database.DatabaseIncludes.Select(item => item.Path).ToList(); SqlServerPlatform = (SqlServerPlatform)database.TargetSqlServerPlatform; SqlServerVersion = (SqlServerVersion)database.TargetSqlServerVersion; TreatTSqlWarningsAsErrors = database.TreatTSqlWarningsAsErrors; if (database.SchemaCompare != null) { SchemaCompare = new SchemaCompare(database.SchemaCompare); } }
/// <exception cref="InvalidOperationException">Unable to perform auto join.</exception> private void AutoJoin(TableData toTable) { JoinPredicate predicate = null; int matchCount = 0; foreach (IQueryableColumn column in toTable.Columns) { if (column.ForeignKeyColumn == null) { continue; } IQueryableColumn foreignKeyColumn = column.ForeignKeyColumn; if (!SchemaCompare.ColumnsAreSame(foreignKeyColumn, QueryTree.Table.PrimaryKey)) { continue; } predicate = new JoinPredicate(foreignKeyColumn, Comparison.Equal, column); matchCount++; } foreach (IQueryableColumn column in QueryTree.Table.Columns) { if (column.ForeignKeyColumn == null) { continue; } IQueryableColumn foreignKeyColumn = column.ForeignKeyColumn; if (!SchemaCompare.ColumnsAreSame(foreignKeyColumn, toTable.PrimaryKey)) { continue; } predicate = new JoinPredicate(column, Comparison.Equal, foreignKeyColumn); matchCount++; } // if (predicate == null) // { // // foreach(IQueryableColumn column in toTable.Columns) // { // if(column.ForeignKeyColumn == null) // continue; // // IQueryableColumn foreignKeyColumn = column.ForeignKeyColumn; // foreach (QueryColumn foreignKeyInnerColumn in foreignKeyColumn.Table.Columns) // { // if(!SchemaCompare.ColumnsAreSame(foreignKeyInnerColumn, QueryTree.Table.PrimaryKey)) // continue; // // predicate = new JoinPredicate(foreignKeyInnerColumn, Comparison.Equal, column); // matchCount++; // } // } // // foreach(IQueryableColumn column in QueryTree.Table.Columns) // { // if(column.ForeignKeyColumn == null) // continue; // // IQueryableColumn foreignKeyColumn = column.ForeignKeyColumn; // foreach (QueryColumn foreignKeyinnerColumn in foreignKeyColumn.Table.Columns) // { // if(!SchemaCompare.ColumnsAreSame(foreignKeyinnerColumn, toTable.PrimaryKey)) // continue; // // predicate = new JoinPredicate(column, Comparison.Equal, foreignKeyinnerColumn); // matchCount++; // } // } // } // if (predicate == null) // throw new InvalidOperationException(string.Format("Unable to map table {0}.{1} to table {2}.{3}.", QueryTree.Table.Owner, QueryTree.Table.Name, toTable.Owner, toTable.Name)); if (matchCount > 1) { throw new InvalidOperationException("Multiple potential joins were found. Unable to perform the auto-join operation."); } if (predicate != null) { QueryTree.Joins.Add(predicate); } }