/// <summary> /// Adds the specified sub query. /// </summary> /// <param name="subQuery">The sub query to consider.</param> /// <returns>Return this added parameter.</returns> public DataExpression UseSubQuery(IDbQuery subQuery) { if (SubQueries == null) SubQueries = new List<DbQuery>(); SubQueries.Add((DbQuery)subQuery); return BdoScript.Function("sqlQuery", SubQueries.Count.ToString()).CreateExp(); }
public virtual IQuery GetOrCreateSubQuery(string propertyName) { propertyName.NotNullOrEmpty(nameof(propertyName)); if (SubQueries.ContainsKey(propertyName)) { return(SubQueries[propertyName]); } var propertyDefinition = EntityDefinition.Properties.SafeGet(propertyName); if (propertyDefinition == null) { throw new QueryException(this, $"Unable to create sub-query for property {propertyName} because it is not a valid property of {EntityDefinition}."); } if (propertyDefinition.PropertyType.DataTypeType != DataTypeType.Relation) { throw new QueryException(this, $"Unable to create sub-query for property {propertyName} because it is not a relation property of {EntityDefinition}."); } var subquery = InternalCreateSubQuery(propertyDefinition.PropertyType.GetTargetValueType(propertyDefinition) as IEntityDefinition); SubQueries[propertyDefinition.Name] = subquery; return(subquery); }
public IEnumerable <string> GetColumnNamesToSelect(AliasedSqlSubQuery subQuery) { var hasExplicitColumnsToSelect = SubQueries.Any(x => x.HasExplicitlySpecifiedColumnsToSelect); if (hasExplicitColumnsToSelect) { return(subQuery.ExplicitlySpecifiedColumnsToSelect); } return(subQuery.AllSelectableColumnNames); }
/// Closes the subquery parts aggregator and adds a subquery as a part of this query. /// /// If a subquery parts aggregator is open and is also visiting a subquery, /// redirects the call to it instead. public void CloseSubQueryExpressionPartsAggregator() { if (_visitingSubQueryExpression && _subQueryExpressionPartsAggregator._visitingSubQueryExpression) { _subQueryExpressionPartsAggregator.CloseSubQueryExpressionPartsAggregator(); } else { if (string.IsNullOrEmpty(SelectPart)) { SelectPart = _subQueryExpressionPartsAggregator.SelectPart; } else { SubQueries.Add(_subQueryExpressionPartsAggregator.BuildQueryStatement().Trim(';')); } _visitingSubQueryExpression = false; } }
private void WrapSubQueryExpressionsToQueryParts() { if (SubQueries.Count != SubQueryLinkActions.Count) { throw new ArgumentException( "Amounts of subqueries and the actions to take with them are not equal."); } for (int i = SubQueries.Count - 1; i >= 0; i--) { var subQuery = SubQueries[i]; var subQueryAction = SubQueryLinkActions[i]; if (subQueryAction.Contains("EXISTS")) { WhereParts.Add(string.Format(subQueryAction, subQuery)); SubQueries.RemoveAt(i); SubQueryLinkActions.RemoveAt(i); } } }
private void CreateSubQuery(string alias, Type type) { var subQuery = AliasedSqlSubQuery.Create(alias, type, _conventionReader); SubQueries.Add(subQuery); }
private bool HasSubQueryForIdentifier(string tableIdentifier) { return(SubQueries.Any(x => x.TableIdentifier == tableIdentifier)); }
private bool HasSubQuery(string tableName, string alias = null) { return(SubQueries.Any(x => x.TableName == tableName && x.Alias == alias)); }
private AliasedSqlSubQuery GetSubQuery(string tableName, string alias) { return(SubQueries.FirstOrDefault(x => x.TableName == tableName && x.Alias == alias)); }