Пример #1
0
        private string GetSelectParameters(SelectClause selectClause, QueryModel queryModel)
        {
            string expression;

            if (selectClause.Selector.GetType() == typeof(QuerySourceReferenceExpression))
            {
                if (_queryPartsAggregator.AggregateFunction == null)
                {
                    expression = GetN1QlExpression(selectClause.Selector);

                    if (_queryPartsAggregator.QueryType != N1QlQueryType.Array)
                    {
                        expression = string.Concat(expression, ".*");
                    }
                }
                else
                {
                    // for aggregates, just use "*" (i.e. AggregateFunction = "COUNT", expression = "*" results in COUNT(*)"

                    expression = "*";
                }
            }
            else if (selectClause.Selector.NodeType == ExpressionType.New)
            {
                if (_queryPartsAggregator.QueryType != N1QlQueryType.Array)
                {
                    var selector = selectClause.Selector as NewExpression;

                    if (_groupingStatus == GroupingStatus.AfterGroupSubquery)
                    {
                        // SELECT clauses must be remapped to refer directly to the extents in the grouping subquery
                        // rather than refering to the output of the grouping subquery

                        selector = (NewExpression)TransformingExpressionTreeVisitor.Transform(selector, _groupingExpressionTransformerRegistry);
                    }

                    expression =
                        N1QlExpressionTreeVisitor.GetN1QlSelectNewExpression(selector, _queryGenerationContext);
                }
                else
                {
                    expression = GetN1QlExpression(selectClause.Selector);
                }
            }
            else
            {
                expression = GetN1QlExpression(selectClause.Selector);

                if ((_queryPartsAggregator.QueryType == N1QlQueryType.Subquery) || (_queryPartsAggregator.QueryType == N1QlQueryType.Array))
                {
                    // For LINQ, this subquery is expected to return a list of the specific property being selected
                    // But N1QL will always return a list of objects with a single property
                    // So we need to use an ARRAY statement to convert the list

                    _queryPartsAggregator.ArrayPropertyExtractionPart = N1QlHelpers.EscapeIdentifier("result");

                    expression += " as " + _queryPartsAggregator.ArrayPropertyExtractionPart;
                }
            }

            return(expression);
        }
        private string GetSelectParameters(SelectClause selectClause, QueryModel queryModel)
        {
            string expression;

            if (selectClause.Selector.GetType() == typeof(QuerySourceReferenceExpression))
            {
                if (_queryPartsAggregator.AggregateFunction == null)
                {
                    expression = GetN1QlExpression(selectClause.Selector);

                    if (_queryPartsAggregator.QueryType != N1QlQueryType.Array)
                    {
                        expression = string.Concat(expression, ".*");
                    }
                }
                else
                {
                    // for aggregates, just use "*" (i.e. AggregateFunction = "COUNT", expression = "*" results in COUNT(*)"

                    ResultExtractionRequired = true;
                    _queryPartsAggregator.PropertyExtractionPart = N1QlHelpers.EscapeIdentifier("result");
                    expression = "*";
                }
            }
            else if (selectClause.Selector.NodeType == ExpressionType.New)
            {
                if (_queryPartsAggregator.QueryType != N1QlQueryType.Array)
                {
                    var selector = selectClause.Selector as NewExpression;

                    if (_groupingStatus == GroupingStatus.AfterGroupSubquery)
                    {
                        // SELECT clauses must be remapped to refer directly to the extents in the grouping subquery
                        // rather than refering to the output of the grouping subquery

                        selector = (NewExpression)TransformingExpressionTreeVisitor.Transform(selector, _groupingExpressionTransformerRegistry);
                    }

                    expression =
                        N1QlExpressionTreeVisitor.GetN1QlSelectNewExpression(selector, _queryGenerationContext);
                }
                else
                {
                    expression = GetN1QlExpression(selectClause.Selector);
                }
            }
            else
            {
                expression = GetN1QlExpression(selectClause.Selector);

                if (_queryPartsAggregator.QueryType == N1QlQueryType.Subquery)
                {
                    // For LINQ, this subquery is expected to return a list of the specific property being selected
                    // But N1QL will always return a list of objects with a single property
                    // So we need to use an ARRAY statement to convert the list

                    _queryPartsAggregator.PropertyExtractionPart = N1QlHelpers.EscapeIdentifier("result");

                    expression += " as " + _queryPartsAggregator.PropertyExtractionPart;
                }
                else
                {
                    // This is a select expression on the main query that doesn't use a "new" clause, and isn't against an extent
                    // So it will return an array of objects with properties, while LINQ is expecting an array of values
                    // Since we can't extract the properties from the object in N1QL like we can with subqueries
                    // We need to indicate to the BucketQueryExecutor that it will need to extract the properties

                    _queryPartsAggregator.PropertyExtractionPart = N1QlHelpers.EscapeIdentifier("result");
                    ResultExtractionRequired = true;
                }
            }

            return(expression);
        }