Example #1
0
 public override void AddSort(object expr, IComparer comparer)
 {
     // sort makes sense only when we are dealing with a query that
     // returns a nodeset.
     Query evalExpr;
     string query = expr as string;
     if (query != null)
     {
         evalExpr = new QueryBuilder().Build(query, out _needContext); // this will throw if expr is invalid
     }
     else
     {
         CompiledXpathExpr xpathExpr = expr as CompiledXpathExpr;
         if (xpathExpr != null)
         {
             evalExpr = xpathExpr.QueryTree;
         }
         else
         {
             throw XPathException.Create(SR.Xp_BadQueryObject);
         }
     }
     SortQuery sortQuery = _query as SortQuery;
     if (sortQuery == null)
     {
         _query = sortQuery = new SortQuery(_query);
     }
     sortQuery.AddSort(evalExpr, comparer);
 }
 private SortQuery(SortQuery other) : base(other)
 {
     this.results = new List<SortKey>(other.results);
     this.comparer = other.comparer.Clone();
     this.qyInput = Query.Clone(other.qyInput);
     base.count = 0;
 }
        public override void AddSort(object expr, IComparer comparer) {
            // sort makes sense only when we are dealing with a query that
            // returns a nodeset.
	        Query evalExpr;
            if (expr is string) {
                evalExpr = new QueryBuilder().Build((string)expr, out needContext); // this will throw if expr is invalid
            } else if (expr is CompiledXpathExpr) {
                evalExpr = ((CompiledXpathExpr)expr).QueryTree;
	        } else {
                throw XPathException.Create(Res.Xp_BadQueryObject);
            }
            SortQuery sortQuery = query as SortQuery;
            if (sortQuery == null) {
                query = sortQuery = new SortQuery(query);
            }
            sortQuery.AddSort(evalExpr, comparer);
        }
 public override void AddSort(object expr, IComparer comparer)
 {
     Query queryTree;
     if (expr is string)
     {
         queryTree = new QueryBuilder().Build((string) expr, out this.needContext);
     }
     else
     {
         if (!(expr is CompiledXpathExpr))
         {
             throw XPathException.Create("Xp_BadQueryObject");
         }
         queryTree = ((CompiledXpathExpr) expr).QueryTree;
     }
     SortQuery query2 = this.query as SortQuery;
     if (query2 == null)
     {
         this.query = query2 = new SortQuery(this.query);
     }
     query2.AddSort(queryTree, comparer);
 }
        public static IOrderedQueryable <TSource> Sort <TSource>(this IOrderedQueryable <TSource> source, IJsonApiContext jsonApiContext, SortQuery sortQuery)
        {
            BaseAttrQuery attr;

            if (sortQuery.IsAttributeOfRelationship)
            {
                attr = new RelatedAttrSortQuery(jsonApiContext, sortQuery);
            }
            else
            {
                attr = new AttrSortQuery(jsonApiContext, sortQuery);
            }

            return(sortQuery.Direction == SortDirection.Descending
                ? source.ThenByDescending(attr.GetPropertyPath())
                : source.ThenBy(attr.GetPropertyPath()));
        }