Exemple #1
0
        /// <summary>
        /// Creates a new <see cref="AliasNode"/> to wrap the results of a subquery with a different alias
        /// </summary>
        /// <param name="select">The subquery to wrap the results of</param>
        /// <param name="identifier">The alias to use for the subquery</param>
        public AliasNode(SelectNode select, Identifier identifier)
        {
            ColumnSet.AddRange(select.ColumnSet);
            Source = select.Source;
            Alias  = identifier.Value;

            // Check for duplicate columns
            var duplicateColumn = select.ColumnSet
                                  .GroupBy(col => col.OutputColumn, StringComparer.OrdinalIgnoreCase)
                                  .Where(g => g.Count() > 1)
                                  .FirstOrDefault();

            if (duplicateColumn != null)
            {
                throw new NotSupportedQueryFragmentException($"The column '{duplicateColumn.Key}' was specified multiple times", identifier);
            }
        }
Exemple #2
0
        public override IDataExecutionPlanNode FoldQuery(IDictionary <string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary <string, Type> parameterTypes, IList <OptimizerHint> hints)
        {
            Source        = Source.FoldQuery(dataSources, options, parameterTypes, hints);
            Source.Parent = this;

            SelectNode.FoldFetchXmlColumns(Source, ColumnSet, dataSources, parameterTypes);
            SelectNode.ExpandWildcardColumns(Source, ColumnSet, dataSources, parameterTypes);

            if (Source is FetchXmlScan fetchXml)
            {
                // Check if all the source and output column names match. If so, just change the alias of the source FetchXML
                if (ColumnSet.All(col => col.SourceColumn == $"{fetchXml.Alias}.{col.OutputColumn}"))
                {
                    fetchXml.Alias = Alias;
                    return(fetchXml);
                }
            }

            return(this);
        }