예제 #1
0
        private static IList <IList <string> > ExtractPaths(Expression expression, INodeTypeProvider nodeTypeProvider, bool selectMode, bool includeProtocolProps, INamingScheme namingScheme)
        {
            var visitor = new PropertyPathExtractionVisitor(nodeTypeProvider, selectMode, includeProtocolProps, namingScheme);

            visitor.VisitExpression(expression);
            return(visitor._paths);
        }
        public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
        {
            var paths = PropertyPathExtractionVisitor.ExtractPaths(selectClause.Selector, _nodeTypeProvider, true, false, _namingScheme, "/");

            if (paths.Count == 0)
            {
                Precedence = 0;
            }
            else if (!paths.SequenceEqual(new[] { "*" }))
            {
                Select = string.Join(",", paths.ToArray());
            }

            base.VisitSelectClause(selectClause, queryModel);
        }
        protected override void VisitOrderings(ObservableCollection <Ordering> orderings, QueryModel queryModel, OrderByClause orderByClause)
        {
            var orders = orderings.SelectMany(ordering => PropertyPathExtractionVisitor.ExtractPaths(ordering.Expression, _nodeTypeProvider, false, true, _namingScheme, ".")
                                              .Select(path => string.Format("{0} {1}", path, ordering.OrderingDirection.ToString().ToLowerInvariant())))
                         .ToList();

            if (orders.Count > 0)
            {
                if (OrderBy != null)
                {
                    OrderBy = "," + OrderBy;
                }
                OrderBy = string.Join(",", orders.ToArray()) + OrderBy;
            }

            base.VisitOrderings(orderings, queryModel, orderByClause);
        }
        public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
        {
            if (resultOperator is AnyResultOperator ||
                resultOperator is CountResultOperator ||
                resultOperator is LongCountResultOperator ||
                resultOperator is FirstResultOperator ||
                resultOperator is SingleResultOperator)
            {
                return;
            }

            var takeOperator = resultOperator as TakeResultOperator;

            if (takeOperator != null)
            {
                var count = takeOperator.GetConstantCount();
                if (Count != null)
                {
                    count = Math.Min(count, Count.Value);
                }

                Count = count;
                return;
            }

            var skipOperator = resultOperator as SkipResultOperator;

            if (skipOperator != null)
            {
                var startIndex = skipOperator.GetConstantCount();
                if (Count != null)
                {
                    Count = Math.Max(Count.Value - startIndex, 0);
                }

                StartIndex = (StartIndex ?? 1) + startIndex;
                return;
            }

            var fetchOperator = resultOperator as FetchResultOperator;

            if (fetchOperator != null)
            {
                var paths = PropertyPathExtractionVisitor.ExtractPaths(fetchOperator.Selector, _nodeTypeProvider, false, false, _namingScheme, "/");
                if (paths.Count > 0)
                {
                    if (Include != null)
                    {
                        Include += ",";
                    }
                    Include += string.Join(",", paths.ToArray());
                }

                return;
            }

            var withPrecedenceOperator = resultOperator as WithPrecedenceResultOperator;

            if (withPrecedenceOperator != null)
            {
                Precedence = Math.Min(Precedence ?? int.MaxValue, withPrecedenceOperator.Precedence);
                return;
            }

            var withExtensionArgOperator = resultOperator as WithExtensionArgResultOperator;

            if (withExtensionArgOperator != null)
            {
                ExtensionArgs[withExtensionArgOperator.Name] = withExtensionArgOperator.Value;
                return;
            }

#if !NET_3_5
            if (resultOperator is ToCollectionAsyncResultOperator)
            {
                return;
            }
#endif

            throw new NotSupportedException(string.Format("Result operator '{0}' not supported", resultOperator.GetType()));
        }