public async Task <StaticPagedList <T> > PaginationAsync <TKey>(int pageIndex, int pageSize, Expression <Func <T, TKey> > orderBy, bool isOrderByAsc = true, Expression <Func <T, bool> > where = null) { long num; long num1 = (long)0; IMongoQueryable <T> mongoQueryable = IMongoCollectionExtensions.AsQueryable <T>(this.Collection, new AggregateOptions() { AllowDiskUse = true }); num = (where != null ? await this.CountAsync(where) : await this.CountAsync()); num1 = num; if (where != null) { mongoQueryable = MongoQueryable.Where <T>(mongoQueryable, where); } if (isOrderByAsc) { mongoQueryable = MongoQueryable.Take <T>(MongoQueryable.Skip <T>(MongoQueryable.OrderBy <T, TKey>(mongoQueryable, orderBy), (pageIndex - 1) * pageSize), pageSize); } else { mongoQueryable = MongoQueryable.Take <T>(MongoQueryable.Skip <T>(MongoQueryable.OrderByDescending <T, TKey>(mongoQueryable, orderBy), (pageIndex - 1) * pageSize), pageSize); } StaticPagedList <T> staticPagedList = new StaticPagedList <T>(mongoQueryable.ToList <T>(), pageIndex, pageSize, (int)num1); return(staticPagedList); }
internal static IQueryable <T> OrderBy <T, TKey>(this IQueryable <T> queryable, Expression <Func <T, TKey> > filter) { if (queryable is IMongoQueryable <T> mongoQueryable) { return(MongoQueryable.OrderBy(mongoQueryable, filter)); } return(Queryable.OrderBy(queryable, filter)); }
public StaticPagedList <T> Pagination <TKey>(int page, int total, Expression <Func <T, TKey> > orderBy, Expression <Func <T, bool> > where = null) { long count = (long)0; IMongoQueryable <T> model = IMongoCollectionExtensions.AsQueryable <T>(this.Collection); count = (where == null ? this.Count() : this.Count(where)); if (where != null) { model = MongoQueryable.Where <T>(model, where); } model = MongoQueryable.Take <T>(MongoQueryable.Skip <T>(MongoQueryable.OrderBy <T, TKey>(model, orderBy), (page - 1) * total), total); return(new StaticPagedList <T>(model.ToList <T>(), page, total, (int)count)); }
public StaticPagedList <T> Pagination <TKey>(int pageIndex, int pageSize, Expression <Func <T, TKey> > orderBy, bool isOrderByAsc = true, Expression <Func <T, bool> > where = null) { long count = (long)0; IMongoQueryable <T> model = IMongoCollectionExtensions.AsQueryable <T>(this.Collection); count = (where == null ? this.Count() : this.Count(where)); if (where != null) { model = MongoQueryable.Where <T>(model, where); } model = MongoQueryable.Take <T>(MongoQueryable.Skip <T>(isOrderByAsc ? MongoQueryable.OrderBy <T, TKey>(model, orderBy) : MongoQueryable.OrderByDescending <T, TKey>(model, orderBy), (pageIndex - 1) * pageSize), pageSize); return(new StaticPagedList <T>(model.ToList <T>(), pageIndex, pageSize, (int)count)); }
public async Task <StaticPagedList <T> > PaginationAsync <TKey>(int page, int total, Expression <Func <T, TKey> > orderBy, Expression <Func <T, bool> > where = null) { long num; long num1 = (long)0; IMongoQueryable <T> mongoQueryable = IMongoCollectionExtensions.AsQueryable <T>(this.Collection); num = (where != null ? await this.CountAsync(where) : await this.CountAsync()); num1 = num; if (where != null) { mongoQueryable = MongoQueryable.Where <T>(mongoQueryable, where); } mongoQueryable = MongoQueryable.Take <T>(MongoQueryable.Skip <T>(MongoQueryable.OrderBy <T, TKey>(mongoQueryable, orderBy), (page - 1) * total), total); StaticPagedList <T> staticPagedList = new StaticPagedList <T>(mongoQueryable.ToList <T>(), page, total, (int)num1); return(staticPagedList); }
public IMongoQueryable <T> Query <TKey>(Expression <Func <T, TKey> > orderBy, params Expression <Func <T, bool> >[] where) { return(MongoQueryable.OrderBy <T, TKey>(this.Query(where), orderBy)); }
public async Task <IEnumerable <T> > AllAsync <TKey>(int page, int total, Expression <Func <T, bool> > where, Expression <Func <T, TKey> > orderBy) { IOrderedMongoQueryable <T> orderedMongoQueryable = MongoQueryable.OrderBy <T, TKey>(MongoQueryable.Take <T>(MongoQueryable.Skip <T>(MongoQueryable.Where <T>(IMongoCollectionExtensions.AsQueryable <T>(this.Collection), where), (page - 1) * total), total), orderBy); return(await IAsyncCursorSourceExtensions.ToListAsync <T>(orderedMongoQueryable, new CancellationToken())); }
public IList <T> All <TKey>(int page, int total, Expression <Func <T, TKey> > orderBy, Expression <Func <T, bool> > where) { return(MongoQueryable.Take <T>(MongoQueryable.Skip <T>(MongoQueryable.OrderBy <T, TKey>(MongoQueryable.Where <T>(IMongoCollectionExtensions.AsQueryable <T>(this.Collection), where), orderBy), (page - 1) * total), total).ToList <T>()); }
public IList <T> All <TKey>(Expression <Func <T, TKey> > orderBy, Expression <Func <T, bool> > where) { return(MongoQueryable.OrderBy <T, TKey>(MongoQueryable.Where <T>(IMongoCollectionExtensions.AsQueryable <T>(this.Collection), where), orderBy).ToList <T>()); }