public Expression CreateExpression(IQueryable query, OeConstantToVariableVisitor constantToVariableVisitor)
        {
            Expression expression;
            var        expressionBuilder = new OeExpressionBuilder(EdmModel, EntitySetAdapter.EntityType);

            expression = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(EntitySetAdapter.EntityType));
            expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments);
            expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter);
            expression = expressionBuilder.ApplySkipToken(expression, SkipTokenParser, ODataUri.SkipToken);
            expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply);
            expression = expressionBuilder.ApplySelect(expression, this);
            expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy);
            expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path);
            expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path);
            expression = expressionBuilder.ApplyCount(expression, IsCountSegment);

            if (!IsCountSegment)
            {
                EntryFactory = CreateEntryFactory(expressionBuilder);
            }

            expression = constantToVariableVisitor.Translate(expression, expressionBuilder.Constants);
            if (ODataUri.QueryCount.GetValueOrDefault())
            {
                CountExpression = CreateCountExpression(query, expression);
            }

            return(SourceVisitor.Translate(query, expression));
        }
Exemple #2
0
        public Expression CreateExpression(OeConstantToVariableVisitor constantToVariableVisitor)
        {
            Expression expression;
            var        expressionBuilder = new OeExpressionBuilder(EdmModel, EntitySetAdapter.EntityType);

            expression = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(EntitySetAdapter.EntityType));
            expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments);
            expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter);
            expression = expressionBuilder.ApplySkipToken(expression, SkipTokenNameValues, ODataUri.OrderBy, IsDatabaseNullHighestValue);
            expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply);
            expression = expressionBuilder.ApplySelect(expression, this);
            expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy);
            expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path);
            expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path);
            expression = expressionBuilder.ApplyCount(expression, IsCountSegment);

            if (!IsCountSegment)
            {
                EntryFactory = CreateEntryFactory(expressionBuilder);
            }
            if (SkipTokenNameValues != null)
            {
                SkipTokenAccessors = OeSkipTokenParser.GetAccessors(expression, ODataUri.OrderBy);
            }

            return(constantToVariableVisitor.Translate(expression, expressionBuilder.Constants));
        }
        public override Expression Translate(ExpandedNavigationSelectItem item)
        {
            var        segment            = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment;
            Expression expression         = Translate(segment);
            Type       navigationItemType = expression.Type;

            Type itemType = OeExpressionHelper.GetCollectionItemType(navigationItemType);

            if (itemType != null)
            {
                var expressionBuilder = new OeExpressionBuilder(_model, itemType);
                expression = expressionBuilder.ApplyFilter(expression, item.FilterOption);
                expression = expressionBuilder.ApplyOrderBy(expression, item.OrderByOption);

                var path = new ODataPath(_path.Union(item.PathToNavigationProperty));
                expression = expressionBuilder.ApplySkip(expression, item.SkipOption, path);
                expression = expressionBuilder.ApplyTake(expression, item.TopOption, path);

                foreach (KeyValuePair <ConstantExpression, ConstantNode> constant in expressionBuilder.Constants)
                {
                    _visitor.AddConstant(constant.Key, constant.Value);
                }
            }

            Expression countExpression = null;

            if (item.CountOption.GetValueOrDefault())
            {
                MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(itemType);
                countExpression = Expression.Call(countMethodInfo, expression);
            }

            if (item.SelectAndExpand.SelectedItems.Any())
            {
                var        path             = new ODataPath(_path.Union(item.PathToNavigationProperty));
                var        selectTranslator = new OeSelectTranslator(_visitor, path);
                Expression nestedExpression = selectTranslator.CreateExpression(expression, item.SelectAndExpand, OeMetadataLevel.Minimal);

                Type nestedType = OeExpressionHelper.GetCollectionItemType(nestedExpression.Type);
                if (nestedType == null)
                {
                    var visitor = new ParameterVisitor(selectTranslator._parameter, expression);
                    nestedExpression = visitor.Visit(nestedExpression);
                    nestedType       = nestedExpression.Type;
                }

                _selectItemInfo.EntryFactory = selectTranslator.CreateNestedEntryFactory(nestedType, _selectItemInfo.EntitySet, _selectItemInfo.ResourceInfo);
                expression = nestedExpression;
            }

            if (countExpression != null)
            {
                return(CreateNavigationLinkInfo(navigationItemType, expression, countExpression));
            }

            return(expression);
        }
Exemple #4
0
        public Expression CreateExpression(out IReadOnlyDictionary <ConstantExpression, ConstantNode> constants)
        {
            Initialize();

            Expression expression;
            var        expressionBuilder = new OeExpressionBuilder(_joinBuilder);

            IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, EntitySetAdapter.EntitySetName);

            expression = OeEnumerableStub.CreateEnumerableStubExpression(EntitySetAdapter.EntityType, entitySet);
            expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments);
            if (ODataUri.Apply == null)
            {
                expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter);
                expression = expressionBuilder.ApplySelect(expression, this);
            }
            else
            {
                expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply);
                expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter);
                expression = expressionBuilder.ApplySkipToken(expression, SkipTokenNameValues, ODataUri.OrderBy, IsDatabaseNullHighestValue); //order by aggregation
                expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy);
                expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path);
                expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path);
            }

            if (ODataUri.Path.LastSegment is CountSegment)
            {
                expression = expressionBuilder.ApplyCount(expression, true);
            }
            else
            {
                OePropertyAccessor[] skipTokenAccessors = OeSkipTokenParser.GetAccessors(expression, ODataUri.OrderBy, _joinBuilder);
                EntryFactory = CreateEntryFactory(expressionBuilder, skipTokenAccessors);
            }

            constants = expressionBuilder.Constants;
            return(expression);
        }
        public Expression CreateExpression(IQueryable query, OeConstantToVariableVisitor constantToVariableVisitor)
        {
            Expression expression;
            var        expressionBuilder = new OeExpressionBuilder(EdmModel, EntitySetAdapter.EntityType);

            expression = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(EntitySetAdapter.EntityType));
            expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments);
            expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter);
            expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply);
            expression = expressionBuilder.ApplySelect(expression, ODataUri.SelectAndExpand, ODataUri.Path, Headers.MetadataLevel);
            expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy);
            expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path);
            expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path);
            expression = expressionBuilder.ApplyCount(expression, IsCountSegment);

            if (!IsCountSegment)
            {
                EntryFactory = CreateEntryFactory(expressionBuilder);
            }

            expression = constantToVariableVisitor.Translate(expression, expressionBuilder.Constants);
            return(SourceVisitor.Translate(query, expression));
        }
Exemple #6
0
        public Expression CreateExpression(OeConstantToVariableVisitor constantToVariableVisitor)
        {
            Expression expression;
            var        expressionBuilder = new OeExpressionBuilder(JoinBuilder);

            IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, EntitySetAdapter.EntitySetName);

            expression = OeEnumerableStub.CreateEnumerableStubExpression(EntitySetAdapter.EntityType, entitySet);
            expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments);
            expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter);
            if (ODataUri.Apply == null)
            {
                expression = expressionBuilder.ApplySelect(expression, this);
            }
            else
            {
                expression = expressionBuilder.ApplySkipToken(expression, SkipTokenNameValues, ODataUri.OrderBy, IsDatabaseNullHighestValue);
                expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply);
                expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy);
                expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path);
                expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path);
            }
            expression = expressionBuilder.ApplyCount(expression, IsCountSegment);

            if (!IsCountSegment)
            {
                EntryFactory = CreateEntryFactory(expressionBuilder);
            }

            if (SkipTokenNameValues != null)
            {
                SkipTokenAccessors = OeSkipTokenParser.GetAccessors(expression, ODataUri.OrderBy, JoinBuilder);
            }

            return(constantToVariableVisitor.Translate(expression, expressionBuilder.Constants));
        }
            public override SelectItemInfo Translate(ExpandedNavigationSelectItem item)
            {
                var segment = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment;

                if (_navigationNextLink && segment.NavigationProperty.Type is IEdmCollectionTypeReference)
                {
                    return(null);
                }

                SelectItemInfo selectItemInfo        = CreateNavigationSelectItemInfo(_model, segment, false, item.CountOption);
                PropertyInfo   navigationClrProperty = _parameter.Type.GetProperty(selectItemInfo.EdmProperty.Name);
                Expression     expression            = Expression.MakeMemberAccess(_parameter, navigationClrProperty);

                Type itemType = OeExpressionHelper.GetCollectionItemType(expression.Type);

                if (itemType != null)
                {
                    var expressionBuilder = new OeExpressionBuilder(_model, itemType);
                    expression = expressionBuilder.ApplyFilter(expression, item.FilterOption);
                    expression = expressionBuilder.ApplyOrderBy(expression, item.OrderByOption);

                    var path = new ODataPath(_path.Union(item.PathToNavigationProperty));
                    expression = expressionBuilder.ApplySkip(expression, item.SkipOption, path);
                    expression = expressionBuilder.ApplyTake(expression, item.TopOption, path);

                    foreach (KeyValuePair <ConstantExpression, ConstantNode> constant in expressionBuilder.Constants)
                    {
                        _visitor.AddConstant(constant.Key, constant.Value);
                    }
                }

                if (item.SelectAndExpand.SelectedItems.Any())
                {
                    var path             = new ODataPath(_path.Union(item.PathToNavigationProperty));
                    var selectTranslator = new OeSelectTranslator(_visitor, path);

                    ParameterExpression parameter = Expression.Parameter(itemType ?? expression.Type);
                    selectTranslator.BuildSelect(item.SelectAndExpand, expression, parameter, _metadataLevel, _navigationNextLink);

                    Expression nestedExpression;
                    Type       nestedType;
                    if (itemType == null)
                    {
                        nestedExpression = selectTranslator.CreateTupleExpression();
                        var visitor = new ParameterVisitor(parameter, expression, segment.NavigationProperty.Type.IsNullable);
                        nestedExpression = visitor.Visit(nestedExpression);
                        nestedType       = nestedExpression.Type;
                    }
                    else
                    {
                        nestedExpression = selectTranslator.CreateSelectExpression(expression, parameter);
                        nestedType       = OeExpressionHelper.GetCollectionItemType(nestedExpression.Type);
                    }

                    selectItemInfo.EntryFactory = selectTranslator.CreateNestedEntryFactory(nestedType, selectItemInfo.EntitySet, selectItemInfo.Resource);
                    expression = nestedExpression;
                }

                selectItemInfo.Expression = expression;
                return(selectItemInfo);
            }