Exemple #1
0
        private static MethodCallExpression CountExpression(ParameterExpression sourceParameter)
        {
            Type       itemType        = OeExpressionHelper.GetCollectionItemType(sourceParameter.Type);
            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(itemType);

            return(Expression.Call(countMethodInfo, sourceParameter));
        }
        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);
        }
        public Expression CreateCountExpression(IQueryable query, Expression expression)
        {
            Type       filterType       = EntryFactory == null ? query.ElementType : EdmModel.GetClrType(EntryFactory.EntityType);
            Expression filterExpression = ODataUri.Filter == null ? query.Expression : FilterVisitor.Translate(query, expression, filterType);

            Type       sourceType      = OeExpressionHelper.GetCollectionItemType(filterExpression.Type);
            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(sourceType);

            return(Expression.Call(countMethodInfo, filterExpression));
        }
        public Expression ApplyCount(Expression source, bool?queryCount)
        {
            if (!queryCount.GetValueOrDefault())
            {
                return(source);
            }

            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(ParameterType);

            return(Expression.Call(countMethodInfo, source));
        }
Exemple #5
0
        private static MethodCallExpression CountDistinctExpression(ParameterExpression sourceParameter, LambdaExpression lambda)
        {
            MethodInfo           selectMetodInfo = OeMethodInfoHelper.GetSelectMethodInfo(lambda.Parameters[0].Type, lambda.ReturnType);
            MethodCallExpression selectCall      = Expression.Call(selectMetodInfo, sourceParameter, lambda);

            MethodInfo           distinctMethodInfo = OeMethodInfoHelper.GetDistinctMethodInfo(lambda.ReturnType);
            MethodCallExpression distinctCall       = Expression.Call(distinctMethodInfo, selectCall);

            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(lambda.ReturnType);

            return(Expression.Call(countMethodInfo, distinctCall));
        }
Exemple #6
0
        public static MethodCallExpression CreateCountExpression(Expression expression)
        {
            var filterVisitor = new FilterVisitor();

            filterVisitor.Visit(expression);

            Expression whereExpression = filterVisitor.WhereExpression;

            if (whereExpression == null)
            {
                whereExpression = filterVisitor.Source;
            }

            Type       sourceType      = OeExpressionHelper.GetCollectionItemType(whereExpression.Type);
            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(sourceType);

            return(Expression.Call(countMethodInfo, whereExpression));
        }
Exemple #7
0
        public MethodCallExpression CreateCountExpression(Expression source)
        {
            if (EntryFactory == null)
            {
                throw new InvalidOperationException("Cannot get count expression for scalar result expression");
            }

            Type sourceType    = EdmModel.GetClrType(EntryFactory.EntitySet);
            var  filterVisitor = new FilterVisitor(sourceType);

            filterVisitor.Visit(source);

            Expression?whereExpression = filterVisitor.WhereExpression;

            if (whereExpression == null)
            {
                whereExpression = filterVisitor.Source;
            }

            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(sourceType);

            return(Expression.Call(countMethodInfo, whereExpression));
        }
Exemple #8
0
        public MethodCallExpression CreateCountExpression(Expression source)
        {
            if (EntryFactory == null)
            {
                return(null);
            }

            Type sourceType    = EdmModel.GetClrType(EntryFactory.EntitySet);
            var  filterVisitor = new FilterVisitor(sourceType);

            filterVisitor.Visit(source);

            Expression whereExpression = filterVisitor.WhereExpression;

            if (whereExpression == null)
            {
                whereExpression = filterVisitor.Source;
            }

            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(sourceType);

            return(Expression.Call(countMethodInfo, whereExpression));
        }