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);
        }
        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);
        }
        internal Expression ProcessResourceRoot(Expression rootExpression, ConstantExpression whereExpression)
        {
            ResourceType resourceType = this.initialResourceRoot.ResourceType;

            DataServiceQueryProvider.ResultSet resultSet = null;
            EntityMetadata item    = this.schema.EntityMetadataDictionary[resourceType.FullName];
            ICommand       command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, resourceType, item, this.membershipId);

            using (command)
            {
                this.InvokeFilteredGet(command, resourceType, null, out resultSet);
            }
            IQueryable <DSResource> dSResources            = resultSet.AsQueryable <DSResource>();
            ExpressionNodeReplacer  expressionNodeReplacer = new ExpressionNodeReplacer(whereExpression, Expression.Constant(dSResources));
            Expression expression = expressionNodeReplacer.Visit(rootExpression);

            return(expression);
        }
 public static Expression GetOptimizedExpression(Expression tree, IQueryable <DSResource> resourceRoot, ResourceType baseResourceType)
 {
     while (true)
     {
         MovableWhereFinder movableWhereFinder = new MovableWhereFinder(tree, resourceRoot, baseResourceType);
         if (movableWhereFinder.MovableWhereExpression == null)
         {
             break;
         }
         MethodCallExpression item            = movableWhereFinder.MovableWhereExpression.Arguments[0] as MethodCallExpression;
         Expression[]         expressionArray = new Expression[2];
         expressionArray[0] = item.Arguments[0];
         expressionArray[1] = movableWhereFinder.MovableWhereExpression.Arguments[1];
         MethodCallExpression methodCallExpression = Expression.Call(movableWhereFinder.MovableWhereExpression.Method, expressionArray);
         Expression[]         item1 = new Expression[2];
         item1[0] = methodCallExpression;
         item1[1] = item.Arguments[1];
         MethodCallExpression   methodCallExpression1  = Expression.Call(item.Method, item1);
         ExpressionNodeReplacer expressionNodeReplacer = new ExpressionNodeReplacer(movableWhereFinder.MovableWhereExpression, methodCallExpression1);
         tree = expressionNodeReplacer.Visit(tree);
     }
     return(tree);
 }
		public static Expression GetOptimizedExpression(Expression tree, IQueryable<DSResource> resourceRoot, ResourceType baseResourceType)
		{
			while (true)
			{
				MovableWhereFinder movableWhereFinder = new MovableWhereFinder(tree, resourceRoot, baseResourceType);
				if (movableWhereFinder.MovableWhereExpression == null)
				{
					break;
				}
				MethodCallExpression item = movableWhereFinder.MovableWhereExpression.Arguments[0] as MethodCallExpression;
				Expression[] expressionArray = new Expression[2];
				expressionArray[0] = item.Arguments[0];
				expressionArray[1] = movableWhereFinder.MovableWhereExpression.Arguments[1];
				MethodCallExpression methodCallExpression = Expression.Call(movableWhereFinder.MovableWhereExpression.Method, expressionArray);
				Expression[] item1 = new Expression[2];
				item1[0] = methodCallExpression;
				item1[1] = item.Arguments[1];
				MethodCallExpression methodCallExpression1 = Expression.Call(item.Method, item1);
				ExpressionNodeReplacer expressionNodeReplacer = new ExpressionNodeReplacer(movableWhereFinder.MovableWhereExpression, methodCallExpression1);
				tree = expressionNodeReplacer.Visit(tree);
			}
			return tree;
		}