예제 #1
0
        public static Expression Compile(
            this QueryableSortContext context,
            Expression source)
        {
            if (context.Operations.Count == 0)
            {
                return(source);
            }

            var firstOperation = true;

            foreach (var operation in context.Operations)
            {
                if (firstOperation &&
                    !OrderingMethodFinder.OrderMethodExists(source))
                {
                    source = operation.CompileOrderBy(source);
                }
                else
                {
                    source = operation.CompileThenBy(source);
                }

                firstOperation = false;
            }

            return(source);
        }
예제 #2
0
 protected override QueryableSortOperation HandleOperation(
     QueryableSortContext context,
     QueryableFieldSelector fieldSelector,
     ISortField field,
     ISortEnumValue?sortEnumValue)
 {
     return(DescendingSortOperation.From(fieldSelector));
 }
예제 #3
0
        public static IQueryable <TSource> Sort <TSource>(
            this QueryableSortContext context,
            IQueryable <TSource> source)
        {
            if (context.Operations.Count == 0)
            {
                return(source);
            }

            return(source.Provider.CreateQuery <TSource>(context.Compile(source.Expression)));
        }
예제 #4
0
        public Func <T[], T[]> Build <T>(IValueNode Sort)
        {
            var visitorContext = new QueryableSortContext(_inputType, true);
            var visitor        = new SortVisitor <QueryableSortContext, QueryableSortOperation>();

            visitor.Visit(Sort, visitorContext);

            Assert.Empty(visitorContext.Errors);

            return(elements => visitorContext.Sort(elements.AsQueryable()).ToArray());
        }