private void ClearDownJoinChain(JoinCondition cond) { var childLinks = _joinConditions.Where(condition => condition.Info.PKeyTable == cond.Info.FTable).ToList(); if (_selectedColumns.Any(column => column.TableName == cond.Info.PKeyTable) || _conditions.Any(col => col.Column.TableName == cond.Info.FTable)) { return; } foreach (var link in childLinks) { ClearDownJoinChain(link); } var parentLinks = _joinConditions.Where(cnd => cond.Info.FTable == cond.Info.PKeyTable).ToList(); foreach (var link in parentLinks) { ClearUpperJoinChain(link); } _requiredTables.Remove(cond.Info.PKeyTable); _joinConditions.Remove(cond); }
private void TryJoin(string newTable) { var prevReqTables = _requiredTables.ToList(); foreach (var table in prevReqTables) { if (table == newTable) { continue; } var path = TryFindPath(newTable, table, new List <string>()); var pathFoundNow = path != null; if (!pathFoundNow) { continue; } foreach (var cond in path) { var newCond = new JoinCondition(cond); if (!_joinConditions.Any(cnd => cnd.Equals(newCond))) { _joinConditions.Add(newCond); } if (!_requiredTables.Contains(cond.FTable)) { _requiredTables.Add(cond.FTable); } if (!_requiredTables.Contains(cond.PKeyTable)) { _requiredTables.Add(cond.PKeyTable); } } } prevReqTables = _requiredTables.ToList(); foreach (var table in prevReqTables) { if (table == newTable) { continue; } var path = TryFindPath(table, newTable, new List <string>()); var pathFoundNow = path != null; if (!pathFoundNow) { continue; } foreach (var cond in path) { var newCond = new JoinCondition(cond); if (!_joinConditions.Any(cnd => cnd.Equals(newCond))) { _joinConditions.Add(newCond); } if (!_requiredTables.Contains(cond.FTable)) { _requiredTables.Add(cond.FTable); } if (!_requiredTables.Contains(cond.PKeyTable)) { _requiredTables.Add(cond.PKeyTable); } } } }