Exemple #1
0
        /// <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();
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public IEnumerable <string> GetColumnNamesToSelect(AliasedSqlSubQuery subQuery)
        {
            var hasExplicitColumnsToSelect = SubQueries.Any(x => x.HasExplicitlySpecifiedColumnsToSelect);

            if (hasExplicitColumnsToSelect)
            {
                return(subQuery.ExplicitlySpecifiedColumnsToSelect);
            }

            return(subQuery.AllSelectableColumnNames);
        }
Exemple #4
0
        /// 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;
            }
        }
Exemple #5
0
        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);
                }
            }
        }
Exemple #6
0
        private void CreateSubQuery(string alias, Type type)
        {
            var subQuery = AliasedSqlSubQuery.Create(alias, type, _conventionReader);

            SubQueries.Add(subQuery);
        }
Exemple #7
0
 private bool HasSubQueryForIdentifier(string tableIdentifier)
 {
     return(SubQueries.Any(x => x.TableIdentifier == tableIdentifier));
 }
Exemple #8
0
 private bool HasSubQuery(string tableName, string alias = null)
 {
     return(SubQueries.Any(x => x.TableName == tableName && x.Alias == alias));
 }
Exemple #9
0
 private AliasedSqlSubQuery GetSubQuery(string tableName, string alias)
 {
     return(SubQueries.FirstOrDefault(x => x.TableName == tableName && x.Alias == alias));
 }