/// <summary> /// 获取给定类型子类对象集合 /// </summary> /// <typeparam name="TSub">子类类型</typeparam> /// <returns>子类对象集合</returns> protected virtual IRavenQueryable <TSub> FindAllInner <TSub>() where TSub : T { IRavenQueryable <TSub> entities = this._dbContext.Query <TSub>(); entities = entities.OrderByDescending(x => x.AddedTime); return(entities); }
/// <summary> /// 分页扩展方法 /// </summary> /// <typeparam name="T">领域实体</typeparam> /// <param name="queryable">集合对象</param> /// <param name="predicate">查询条件</param> /// <param name="pageIndex">页索引</param> /// <param name="pageSize">页容量</param> /// <param name="rowCount">总记录条数</param> /// <param name="pageCount">总页数</param> /// <returns>对象集合</returns> public static IRavenQueryable <T> ToPage <T>(this IRavenQueryable <T> queryable, Expression <Func <T, bool> > predicate, int pageIndex, int pageSize, out int rowCount, out int pageCount) where T : PlainEntity { IRavenQueryable <T> list = queryable.Where(predicate); rowCount = list.Count(); pageCount = (int)Math.Ceiling(rowCount * 1.0 / pageSize); return(list.OrderByDescending(x => x.AddedTime).Skip((pageIndex - 1) * pageSize).Take(pageSize)); }
/// <summary> /// 获取给定类型子类对象集合 /// </summary> /// <typeparam name="TSub">子类类型</typeparam> /// <returns>子类对象集合</returns> protected override IRavenQueryable <TSub> FindAllInner <TSub>() { IRavenQueryable <TSub> entities = this._dbContext.Query <TSub>(); entities = entities.Where(x => !x.Deleted); entities = entities.OrderByDescending(x => x.AddedTime); return(entities); }
public Task <IList <Event> > GetAll(bool descending) { IRavenQueryable <Event> query = DbSession.Query <Event>(); if (descending) { query = query.OrderByDescending(e => e.Number); } else { query = query.OrderBy(e => e.Number); } return(query.ToListAsync()); }
static IQueryable <TUserAuth> SortAndPage(IRavenQueryable <TUserAuth> q, string orderBy, int?skip, int?take) { var qEnum = q.AsQueryable(); if (!string.IsNullOrEmpty(orderBy)) { orderBy = AuthRepositoryUtils.ParseOrderBy(orderBy, out var desc); qEnum = desc ? q.OrderByDescending(orderBy) : q.OrderBy(orderBy); } if (skip != null) { qEnum = qEnum.Skip(skip.Value); } if (take != null) { qEnum = qEnum.Take(take.Value); } return(qEnum); }
private static IRavenQueryable <T> OrderBy <T>( this IRavenQueryable <T> query, string sortBy, string sortDirection = "asc") { if (string.IsNullOrWhiteSpace(sortBy)) { return(query); } var param = Expression.Parameter(typeof(T), "item"); var sortExpression = Expression.Lambda <Func <T, object> > (Expression.Convert(Expression.Property(param, sortBy), typeof(object)), param); switch (sortDirection.ToLower()) { case "asc": return(query.OrderBy <T, object>(sortExpression)); default: return(query.OrderByDescending <T, object>(sortExpression)); } }
public static IRavenQueryable <RecentPopularTags.ReduceResult> OrderByCountDescending( this IRavenQueryable <RecentPopularTags.ReduceResult> query) { return(query.OrderByDescending(x => x.Count)); }
public static IRavenQueryable <TSource> Sort <TSource>(this IRavenQueryable <TSource> source, Request request, Expression <Func <TSource, object> > defaultKeySelector = null, string defaultSortDirection = "desc") where TSource : MessagesViewIndex.SortAndFilterOptions { var direction = defaultSortDirection; if (request.Query.direction.HasValue) { direction = (string)request.Query.direction; } if (direction != "asc" && direction != "desc") { direction = defaultSortDirection; } var sortOptions = new[] { "processed_at", "id", "message_type", "time_sent", "critical_time", "delivery_time", "processing_time", "status", "message_id" }; var sort = "time_sent"; Expression <Func <TSource, object> > keySelector; if (request.Query.sort.HasValue) { sort = (string)request.Query.sort; } if (!sortOptions.Contains(sort)) { sort = "time_sent"; } switch (sort) { case "id": case "message_id": keySelector = m => m.MessageId; break; case "message_type": keySelector = m => m.MessageType; break; case "critical_time": keySelector = m => m.CriticalTime; break; case "delivery_time": keySelector = m => m.DeliveryTime; break; case "processing_time": keySelector = m => m.ProcessingTime; break; case "processed_at": keySelector = m => m.ProcessedAt; break; case "status": keySelector = m => m.Status; break; default: if (defaultKeySelector == null) { keySelector = m => m.TimeSent; } else { keySelector = defaultKeySelector; } break; } if (direction == "asc") { return(source.OrderBy(keySelector)); } return(source.OrderByDescending(keySelector)); }
private IRavenQueryable <CustomFieldIndexedForList> ApplySorting(IRavenQueryable <CustomFieldIndexedForList> query, CustomFieldListGetRequest dto) { if (dto.OrderBy == CustomFieldOrderColumns.Default) { dto.OrderBy = CustomFieldOrderColumns.Name; dto.OrderDirection = OrderDirections.Asc; } return(dto.OrderBy switch { CustomFieldOrderColumns.Name or CustomFieldOrderColumns.Default => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.Name) : query.OrderByDescending(t => t.Name), CustomFieldOrderColumns.Type => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.FieldType) : query.OrderByDescending(t => t.FieldType), _ => throw new ArgumentOutOfRangeException($"Unsupported 'order by' - {dto.OrderBy}") });
private IRavenQueryable <UserIndexedForList> ApplySorting(IRavenQueryable <UserIndexedForList> query, UserListGetRequest dto) { if (dto.OrderBy == UsersOrderColumns.Default) { if (IsSearchResult) { return(query); // Use default order by relevance. Otherwise descending sort by number } dto.OrderBy = UsersOrderColumns.Name; dto.OrderDirection = OrderDirections.Asc; } return(dto.OrderBy switch { UsersOrderColumns.Name => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.FullName) : query.OrderByDescending(t => t.FullName), UsersOrderColumns.Email => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.Email) : query.OrderByDescending(t => t.Email), UsersOrderColumns.RegistrationDate => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.RegistrationDate) : query.OrderByDescending(t => t.RegistrationDate), _ => throw new NotImplementedException() });
private IEnumerable<Post> OrderByDateDescending(IRavenQueryable<Post> query) { return query.OrderByDescending(p => p.Date); }
private IEnumerable <Post> OrderByDateDescending(IRavenQueryable <Post> query) { return(query.OrderByDescending(p => p.Date)); }