internal static IQueryable Deserialize(DomainServiceDescription domainServiceDescription, IQueryable query, IEnumerable<ServiceQueryPart> queryParts, QueryResolver queryResolver)
        {
            foreach (ServiceQueryPart part in queryParts)
            {
                switch (part.QueryOperator)
                {
                    case "where":
                        query = DynamicQueryable.Where(query, part.Expression, queryResolver);
                        break;
                    case "orderby":
                        query = DynamicQueryable.OrderBy(query, part.Expression, queryResolver);
                        break;
                    case "skip":
                        query = DynamicQueryable.Skip(query, Convert.ToInt32(part.Expression, System.Globalization.CultureInfo.InvariantCulture));
                        break;
                    case "take":
                        query = DynamicQueryable.Take(query, Convert.ToInt32(part.Expression, System.Globalization.CultureInfo.InvariantCulture));
                        break;
                }
            }

            // Perform any required post processing transformations to the
            // expression tree
            Expression expr = PostProcessor.Process(domainServiceDescription, query.Expression);
            query = query.Provider.CreateQuery(expr);

            return query;
        }
 public static IQueryable Where(this IQueryable source, string predicate, QueryResolver queryResolver)
 {
     if (source == null)
         throw new ArgumentNullException("source");
     if (predicate == null)
         throw new ArgumentNullException("predicate");
     LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(bool), predicate, queryResolver);
     return source.Provider.CreateQuery(
         Expression.Call(
             typeof(Queryable), "Where",
             new Type[] { source.ElementType },
             source.Expression, Expression.Quote(lambda)));
 }
 public static IQueryable OrderBy(this IQueryable source, string ordering, QueryResolver queryResolver)
 {
     if (source == null)
         throw new ArgumentNullException("source");
     if (ordering == null)
         throw new ArgumentNullException("ordering");
     ParameterExpression[] parameters = new ParameterExpression[] {
         Expression.Parameter(source.ElementType, "") };
     ExpressionParser parser = new ExpressionParser(parameters, ordering, queryResolver);
     IEnumerable<DynamicOrdering> orderings = parser.ParseOrdering();
     Expression queryExpr = source.Expression;
     string methodAsc = "OrderBy";
     string methodDesc = "OrderByDescending";
     foreach (DynamicOrdering o in orderings)
     {
         queryExpr = Expression.Call(
             typeof(Queryable), o.Ascending ? methodAsc : methodDesc,
             new Type[] { source.ElementType, o.Selector.Type },
             queryExpr, Expression.Quote(DynamicExpression.Lambda(o.Selector, parameters)));
         methodAsc = "ThenBy";
         methodDesc = "ThenByDescending";
     }
     return source.Provider.CreateQuery(queryExpr);
 }
Exemple #4
0
        internal static IQueryable Deserialize(DomainServiceDescription domainServiceDescription, IQueryable query, IEnumerable <ServiceQueryPart> queryParts, QueryResolver queryResolver)
        {
            foreach (ServiceQueryPart part in queryParts)
            {
                switch (part.QueryOperator)
                {
                case "where":
                    query = DynamicQueryable.Where(query, part.Expression, queryResolver);
                    break;

                case "orderby":
                    query = DynamicQueryable.OrderBy(query, part.Expression, queryResolver);
                    break;

                case "skip":
                    query = DynamicQueryable.Skip(query, Convert.ToInt32(part.Expression, System.Globalization.CultureInfo.InvariantCulture));
                    break;

                case "take":
                    query = DynamicQueryable.Take(query, Convert.ToInt32(part.Expression, System.Globalization.CultureInfo.InvariantCulture));
                    break;
                }
            }

            // Perform any required post processing transformations to the
            // expression tree
            Expression expr = PostProcessor.Process(domainServiceDescription, query.Expression);

            query = query.Provider.CreateQuery(expr);

            return(query);
        }
 public static LambdaExpression ParseLambda(ParameterExpression[] parameters, Type resultType, string expression, QueryResolver queryResolver)
 {
     ExpressionParser parser = new ExpressionParser(parameters, expression, queryResolver);
     return Lambda(parser.Parse(resultType), parameters);
 }
 public static LambdaExpression ParseLambda(Type itType, Type resultType, string expression, QueryResolver queryResolver)
 {
     return ParseLambda(new ParameterExpression[] { Expression.Parameter(itType, "") }, resultType, expression, queryResolver);
 }
 public ExpressionParser(ParameterExpression[] parameters, string expression, QueryResolver queryResolver)
 {
     if (expression == null)
         throw new ArgumentNullException("expression");
     if (keywords == null)
         keywords = CreateKeywords();
     this.queryResolver = queryResolver;
     symbols = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
     literals = new Dictionary<Expression, string>();
     if (parameters != null)
         ProcessParameters(parameters);
     text = expression;
     textLen = text.Length;
     SetTextPos(0);
     NextToken();
 }