Ejemplo n.º 1
0
        private Expression BuildSkipTakeSource(Expression source, OeSkipTokenNameValue[] skipTokenNameValues, bool isDatabaseNullHighestValue)
        {
            BuildOrderBySkipTake(_rootNavigationItem, _odataUri.OrderBy, HasSelectItems(_odataUri.SelectAndExpand));
            source = BuildJoin(source, new OeNavigationSelectItem[] { _rootNavigationItem });

            long?top = GetTop(_rootNavigationItem, _odataUri.Top);

            if (top == null && _odataUri.Skip == null)
            {
                return(source);
            }

            var expressionBuilder = new OeExpressionBuilder(_joinBuilder);

            source = expressionBuilder.ApplySkipToken(source, skipTokenNameValues, _odataUri.OrderBy, isDatabaseNullHighestValue);
            source = expressionBuilder.ApplyOrderBy(source, _odataUri.OrderBy);
            source = expressionBuilder.ApplySkip(source, _odataUri.Skip, _odataUri.Path);
            return(expressionBuilder.ApplyTake(source, top, _odataUri.Path));

            bool HasSelectItems(SelectExpandClause selectExpandClause)
            {
                if (selectExpandClause != null)
                {
                    foreach (SelectItem odataSelectItem in selectExpandClause.SelectedItems)
                    {
                        if (odataSelectItem is PathSelectItem pathSelectItem && pathSelectItem.SelectedPath.LastSegment is PropertySegment)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
        }
Ejemplo n.º 2
0
        public MethodCallExpression Build(Expression outer, Expression inner, ODataPath odataPath, OrderByClause orderBy, long?skip, long?top)
        {
            var segment = (NavigationPropertySegment)odataPath.LastSegment;
            IEdmNavigationProperty navigationProperty = segment.NavigationProperty;

            if (navigationProperty.ContainsTarget)
            {
                ModelBuilder.ManyToManyJoinDescription joinDescription = _edmModel.GetManyToManyJoinDescription(navigationProperty);
                IEdmEntitySet joinEntitySet = OeEdmClrHelper.GetEntitySet(_edmModel, joinDescription.JoinNavigationProperty);
                outer = OeEnumerableStub.CreateEnumerableStubExpression(joinDescription.JoinClassType, joinEntitySet);
                navigationProperty = joinDescription.TargetNavigationProperty;
            }

            Type outerType = OeExpressionHelper.GetCollectionItemType(outer.Type);
            ParameterExpression outerParameter = Expression.Parameter(outerType, outerType.Name);

            inner = new ReplaceParameterVisitor(outerParameter).Visit(inner); //replace $it
            Expression subquery = CreateWhereExpression(outerParameter, inner, navigationProperty);

            subquery = _expressionBuilder.ApplyOrderBy(subquery, orderBy);
            subquery = _expressionBuilder.ApplySkip(subquery, skip, odataPath);
            subquery = _expressionBuilder.ApplyTake(subquery, top, odataPath);

            Type       innerType            = OeExpressionHelper.GetCollectionItemType(inner.Type);
            MethodInfo selectManyMethdoInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(outerType, innerType);

            return(Expression.Call(selectManyMethdoInfo, outer, Expression.Lambda(subquery, outerParameter)));
        }
Ejemplo n.º 3
0
        private static Expression BuildSkipTakeSource(Expression source, OeQueryContext queryContext, OeSelectItem navigationItem)
        {
            bool hasSelectItems = HasSelectItems(queryContext.ODataUri.SelectAndExpand);

            source = BuildOrderBySkipToken(navigationItem, queryContext.ODataUri.OrderBy, source, queryContext.JoinBuilder, hasSelectItems);
            queryContext.JoinBuilder.Visitor.ChangeParameterType(source);

            var expressionBuilder = new OeExpressionBuilder(queryContext.JoinBuilder);

            source = expressionBuilder.ApplySkipToken(source, queryContext.SkipTokenNameValues, queryContext.ODataUri.OrderBy, queryContext.IsDatabaseNullHighestValue);
            source = expressionBuilder.ApplyOrderBy(source, queryContext.ODataUri.OrderBy);
            source = expressionBuilder.ApplySkip(source, queryContext.ODataUri.Skip, queryContext.ODataUri.Path);
            return(expressionBuilder.ApplyTake(source, queryContext.ODataUri.Top, queryContext.ODataUri.Path));
        }
Ejemplo n.º 4
0
        public static MethodCallExpression Build(Expression outer, Expression inner, ExpandedNavigationSelectItem item, ODataPath odataPath, OeExpressionBuilder expressionBuilder)
        {
            var segment = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment;

            Type       outerType      = OeExpressionHelper.GetCollectionItemType(outer.Type);
            var        outerParameter = Expression.Parameter(outerType, outerType.Name);
            Expression subquery       = CreateWhereExpression(outerParameter, inner, segment.NavigationProperty);

            subquery = expressionBuilder.ApplyOrderBy(subquery, item.OrderByOption);
            subquery = expressionBuilder.ApplySkip(subquery, item.SkipOption, odataPath);
            subquery = expressionBuilder.ApplyTake(subquery, item.TopOption, odataPath);

            Type       innerType            = OeExpressionHelper.GetCollectionItemType(inner.Type);
            MethodInfo selectManyMethdoInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(outerType, innerType);

            return(Expression.Call(selectManyMethdoInfo, outer, Expression.Lambda(subquery, outerParameter)));
        }
Ejemplo n.º 5
0
        private Expression BuildSkipTakeSource(Expression source, OeSkipTokenNameValue[] skipTokenNameValues, bool isDatabaseNullHighestValue)
        {
            BuildOrderBySkipTake(_rootNavigationItem, _odataUri.OrderBy, HasSelectItems(_odataUri.SelectAndExpand));
            source = BuildJoin(source, new OeNavigationSelectItem[] { _rootNavigationItem });

            long?top = GetTop(_rootNavigationItem, _odataUri.Top);

            if (top == null && _odataUri.Skip == null)
            {
                return(source);
            }

            var expressionBuilder = new OeExpressionBuilder(_joinBuilder);

            source = expressionBuilder.ApplySkipToken(source, skipTokenNameValues, _odataUri.OrderBy, isDatabaseNullHighestValue);
            source = expressionBuilder.ApplyOrderBy(source, _odataUri.OrderBy);
            source = expressionBuilder.ApplySkip(source, _odataUri.Skip, _odataUri.Path);
            return(expressionBuilder.ApplyTake(source, top, _odataUri.Path));