public static bool OrderMethodExists(Expression expression) { var visitor = new OrderingMethodFinder(); visitor.Visit(expression); return(visitor._orderingMethodFound); }
internal static async Task <List <LogMessage> > ApplyOrderingQuery(IEnumerable <Tuple <string, bool> > sortBy, IQueryable <LogMessage> query, int skip, int take) { List <Tuple <string, bool> > rules = sortBy.ToList(); try { for (int index = 0; index < rules.Count; index++) { Tuple <string, bool> rule = rules[index]; if (rule.Item1 == nameof(DataTableTelemetryData.Timestamp) || rule.Item1 == nameof(DataTableTelemetryData.ProgramVersion) || rule.Item1 == nameof(DataTableTelemetryData.UserName)) { query = GenericOrder(query, rule.Item1, rule.Item2, index); } else if (rule.Item1 == nameof(DataTableTelemetryData.EntryKey)) { query = GenericOrder(query, nameof(ExceptionInfo.TypeName), rule.Item2, index); } } IOrderedQueryable <LogMessage> orderedQuery = query as IOrderedQueryable <LogMessage>; if (!OrderingMethodFinder.OrderMethodExists(orderedQuery.Expression)) { orderedQuery = query.OrderByDescending(x => x.Timestamp); } return(await orderedQuery.Skip(skip).Take(take).ToListAsync().ConfigureAwait(false)); } catch (Exception) { return(await query.OrderByDescending(x => x.Timestamp).Skip(skip).Take(take).ToListAsync().ConfigureAwait(false)); } }
public static Expression Compile( this QueryableSortContext context, Expression source) { if (context.Operations.Count == 0) { return(source); } var firstOperation = true; foreach (QueryableSortOperation?operation in context.Operations) { if (firstOperation && !OrderingMethodFinder.OrderMethodExists(source)) { source = operation.CompileOrderBy(source); } else { source = operation.CompileThenBy(source); } firstOperation = false; } return(source); }
public IQueryable <TSource> Sort <TSource>( IQueryable <TSource> source) { if (!SortOperations.Any()) { return(source); } IOrderedQueryable <TSource> sortedSource; if (!OrderingMethodFinder.OrderMethodExists(source.Expression)) { sortedSource = source.AddInitialSortOperation( SortOperations.Dequeue()); } else { sortedSource = (IOrderedQueryable <TSource>)source; } while (SortOperations.Any()) { sortedSource = sortedSource.AddSortOperation( SortOperations.Dequeue()); } return(sortedSource); }
public IQueryable <TSource> Apply(IQueryable <TSource> queryable) { var visitor = new OrderingMethodFinder(); visitor.Visit(queryable.Expression); if (visitor.OrderingMethodFound) { queryable = Direction == ListSortDirection.Ascending ? ((IOrderedQueryable <TSource>)queryable).ThenBy(Filter) : ((IOrderedQueryable <TSource>)queryable).ThenByDescending(Filter); } else { queryable = Direction == ListSortDirection.Ascending ? queryable.OrderBy(Filter) : queryable.OrderByDescending(Filter); } return(queryable); }
public Expression Compile( Expression source) { if (Instance.Count == 0) { return(source); } if (!OrderingMethodFinder.OrderMethodExists(source)) { source = source.CompileInitialSortOperation( Instance.Dequeue(), _parameter); } while (Instance.Count != 0) { source = source.CompileSortOperation( Instance.Dequeue(), _parameter); } return(source); }
public static Expression Compile( this QueryableSortVisitorContext context, Expression source) { if (context.SortOperations.Count == 0) { return(source); } if (!OrderingMethodFinder.OrderMethodExists(source)) { source = source.CompileInitialSortOperation( context.SortOperations.Dequeue()); } while (context.SortOperations.Count != 0) { source = source.CompileSortOperation( context.SortOperations.Dequeue()); } return(source); }
public static bool IsOrderingMethodFound <T>(IQueryable <T> queryable) where T : class { return(OrderingMethodFinder.OrderMethodExists(queryable.Expression)); }