Ejemplo n.º 1
0
        internal Expression ProcessWhereWithResourceRoot(Expression rootExpression, MethodCallExpression whereExpression, bool insideNavPropertyWithGetReferenceCmdlet = false)
        {
            ICommand         command;
            LambdaExpression operand = (LambdaExpression)((UnaryExpression)whereExpression.Arguments[1]).Operand;

            operand = (LambdaExpression)PartialEvaluator.Eval(operand);
            ResourceType   initialResourceType = this.GetInitialResourceType();
            EntityMetadata entityMetadatum     = this.schema.EntityMetadataDictionary[initialResourceType.FullName];

            if (!insideNavPropertyWithGetReferenceCmdlet)
            {
                command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, initialResourceType, entityMetadatum, this.membershipId);
            }
            else
            {
                command = new ReferenceInstanceBuilderCommand(initialResourceType, entityMetadatum);
            }
            DataServiceQueryProvider.ResultSet resultSet = null;
            using (command)
            {
                operand = this.InvokeFilteredGet(command, initialResourceType, operand, out resultSet);
            }
            DSMethodTranslatingVisitor dSMethodTranslatingVisitor = new DSMethodTranslatingVisitor(this.resultSets);

            operand = dSMethodTranslatingVisitor.VisitAndConvert <LambdaExpression>(operand, "ProcessWhereWithResourceRoot");
            Func <DSResource, bool> func                   = (Func <DSResource, bool>)operand.Compile();
            IQueryable <DSResource> dSResources            = resultSet.Where <DSResource>((DSResource item) => func(item)).AsQueryable <DSResource>();
            ExpressionNodeReplacer  expressionNodeReplacer = new ExpressionNodeReplacer(whereExpression, Expression.Constant(dSResources));
            Expression expression = expressionNodeReplacer.Visit(rootExpression);

            return(expression);
        }
Ejemplo n.º 2
0
        internal Expression ProcessNestedWhereOfResourceRoot(Expression rootExpression, MethodCallExpression whereExpression, bool insideNavPropertyWithGetReferenceCmdlet = false)
        {
            ICommand       referenceInstanceBuilderCommand;
            ResourceType   initialResourceType = this.GetInitialResourceType();
            EntityMetadata item = this.schema.EntityMetadataDictionary[initialResourceType.FullName];

            DataServiceQueryProvider.ResultSet resultSet = new DataServiceQueryProvider.ResultSet(initialResourceType);
            Expression expression = null;

            if (insideNavPropertyWithGetReferenceCmdlet)
            {
                referenceInstanceBuilderCommand = new ReferenceInstanceBuilderCommand(initialResourceType, item);
            }
            else
            {
                referenceInstanceBuilderCommand = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, initialResourceType, item, this.membershipId);
            }
            using (referenceInstanceBuilderCommand)
            {
                UriParametersHelper.AddParametersToCommand(referenceInstanceBuilderCommand, DataServiceController.Current.GetCurrentResourceUri());
                this.TryAddingAllExpressions(rootExpression, whereExpression, referenceInstanceBuilderCommand, resultSet, out expression);
                this.InvokeCommandWithQuota(referenceInstanceBuilderCommand, resultSet);
            }
            IQueryable <DSResource> dSResources            = resultSet.AsQueryable <DSResource>();
            ExpressionNodeReplacer  expressionNodeReplacer = new ExpressionNodeReplacer(expression, Expression.Constant(dSResources));
            Expression expression1 = expressionNodeReplacer.Visit(rootExpression);

            return(expression1);
        }