public TResult Execute <TResult>(Expression expression) { if (expression.NodeType == ExpressionType.Constant || !(expression is MethodCallExpression)) { return((TResult)DataProvider.GetItems(Set)); } var whereFinder = new InnermostWhereFinder(); var whereExpression = whereFinder.GetInnermostWhere(expression); var lambdaExpression = (LambdaExpression)((UnaryExpression)(whereExpression.Arguments[1])).Operand; return(default(TResult)); }
internal static object Execute(Expression expression, bool IsEnumerable) { if (!IsQueryOverDataSource(expression)) { throw new InvalidProgramException("No query over the data source was specified."); } //// Find the call to Where() and get the lambda expression predicate. InnermostWhereFinder whereFinder = new InnermostWhereFinder(); MethodCallExpression whereExpression = whereFinder.GetInnermostWhere(expression); LambdaExpression lambdaExpression = (LambdaExpression)((UnaryExpression)(whereExpression.Arguments[1])).Operand; // Send the lambda expression through the partial evaluator. lambdaExpression = (LambdaExpression)Evaluator.PartialEval(lambdaExpression); //// Get the place name(s) to query the Web service with. //LocationFinder lf = new LocationFinder(lambdaExpression.Body); //List<string> locations = lf.Locations; //if (locations.Count == 0) // throw new InvalidQueryException("You must specify at least one place name in your query."); //// Call the Web service and get the results. //Place[] places = WebServiceHelper.GetPlacesFromTerraServer(locations); //// Copy the IEnumerable places to an IQueryable. //IQueryable<JObject> queryablePlaces = places.AsQueryable<JObject>(); //// Copy the expression tree that was passed in, changing only the first //// argument of the innermost MethodCallExpression. //ExpressionTreeModifier treeCopier = new ExpressionTreeModifier(queryablePlaces); //Expression newExpressionTree = treeCopier.Visit(expression); //// This step creates an IQueryable that executes by replacing Queryable methods with Enumerable methods. //if (IsEnumerable) // return queryablePlaces.Provider.CreateQuery(newExpressionTree); //else // return queryablePlaces.Provider.Execute(newExpressionTree); return(null); }