public async Task <StaticPagedList <T> > PaginationAsync(int page, int total, SortDefinition <T> sortBy, Expression <Func <T, bool> > query = null) { StaticPagedList <T> staticPagedList; CancellationToken cancellationToken; long num = (long)0; if (query != null) { IMongoCollection <T> collection = this.Collection; FilterDefinition <T> filterDefinition = query; cancellationToken = new CancellationToken(); num = await collection.CountAsync(filterDefinition, null, cancellationToken); IFindFluent <T, T> findFluent = IMongoCollectionExtensions.Find <T>(this.Collection, query, null).Skip(new int?((page - 1) * total)).Limit(new int?(total)).Sort(sortBy); cancellationToken = new CancellationToken(); List <T> listAsync = await IAsyncCursorSourceExtensions.ToListAsync <T>(findFluent, cancellationToken); staticPagedList = new StaticPagedList <T>(listAsync, page, total, (int)num); } else { IMongoCollection <T> mongoCollection = this.Collection; FilterDefinition <T> bsonDocument = new BsonDocument(); cancellationToken = new CancellationToken(); num = await mongoCollection.CountAsync(bsonDocument, null, cancellationToken); IFindFluent <T, T> findFluent1 = IMongoCollectionExtensions.Find <T>(this.Collection, new BsonDocument(), null).Skip(new int?((page - 1) * total)).Limit(new int?(total)).Sort(sortBy); cancellationToken = new CancellationToken(); List <T> ts = await IAsyncCursorSourceExtensions.ToListAsync <T>(findFluent1, cancellationToken); staticPagedList = new StaticPagedList <T>(ts, page, total, (int)num); } return(staticPagedList); }
public static Task <List <T> > ToListAsync <T>(this IQueryable <T> queryable) { if (queryable is IMongoQueryable <T> mongoQueryable) { return(IAsyncCursorSourceExtensions.ToListAsync(mongoQueryable)); } return(Task.FromResult(queryable.ToList())); }
public static async Task <List <T> > ToListAsync <T>(this IQueryable <T> queryable) { if (queryable is IMongoQueryable <T> mongoQueryable) { return(await IAsyncCursorSourceExtensions.ToListAsync(mongoQueryable)); } else { return(queryable.ToList()); } }
public async Task <StaticPagedList <T> > PaginationAsync(int page, int total, SortDefinition <T> sortBy, FilterDefinition <T> query) { long num = (long)0; IMongoCollection <T> collection = this.Collection; FilterDefinition <T> filterDefinition = query; CancellationToken cancellationToken = new CancellationToken(); num = await collection.CountAsync(filterDefinition, null, cancellationToken); IFindFluent <T, T> findFluent = IMongoCollectionExtensions.Find <T>(this.Collection, query, null).Skip(new int?((page - 1) * total)).Limit(new int?(total)).Sort(sortBy); cancellationToken = new CancellationToken(); List <T> listAsync = await IAsyncCursorSourceExtensions.ToListAsync <T>(findFluent, cancellationToken); return(new StaticPagedList <T>(listAsync, page, total, (int)num)); }
public async Task <IEnumerable <T> > AllAsync(FilterDefinition <T> query, SortDefinition <T> sortBy = null) { IEnumerable <T> listAsync; CancellationToken cancellationToken; IFindFluent <T, T> findFluent = IMongoCollectionExtensions.Find <T>(this.Collection, query, null); if (sortBy == null) { IFindFluent <T, T> findFluent1 = findFluent; cancellationToken = new CancellationToken(); listAsync = await IAsyncCursorSourceExtensions.ToListAsync <T>(findFluent1, cancellationToken); } else { IFindFluent <T, T> findFluent2 = findFluent.Sort(sortBy); cancellationToken = new CancellationToken(); listAsync = await IAsyncCursorSourceExtensions.ToListAsync <T>(findFluent2, cancellationToken); } return(listAsync); }
public Task <List <TProjection> > AggregateAsync <TProjection>(Expression <Func <TEntity, bool> > filterExp, ProjectionDefinition <TEntity, TProjection> group, Expression <Func <TEntity, object> > sortExp = null, SortType sortType = SortType.Ascending, int limit = 0, int skip = 0, ReadPreference readPreference = null) { FilterDefinition <TEntity> filter = null; if (filterExp != null) { filter = Filter.Where(filterExp); } else { filter = Filter.Empty; } IAggregateFluent <TProjection> fluent2 = CreateAggregate(filterExp, CreateSortDefinition(sortExp, sortType), readPreference).Group(group); if (skip > 0) { fluent2 = fluent2.Skip(skip); } if (limit > 0) { fluent2 = fluent2.Limit(limit); } return(IAsyncCursorSourceExtensions.ToListAsync(fluent2)); }
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 async Task <IEnumerable <T> > AllAsync() { IFindFluent <T, T> findFluent = IMongoCollectionExtensions.Find <T>(this.Collection, new BsonDocument(), null); return(await IAsyncCursorSourceExtensions.ToListAsync <T>(findFluent, new CancellationToken())); }
public static async Task <List <T> > ToListAsync <T>(this IQueryable <T> queryable) => queryable is IMongoQueryable <T> mq ? await IAsyncCursorSourceExtensions.ToListAsync(mq) : queryable.ToList();
public static Task <List <TEntity> > ToListAsync <TEntity>(this IQueryable <TEntity> source, CancellationToken cancellationToken = default) => IAsyncCursorSourceExtensions.ToListAsync((IMongoQueryable <TEntity>)source, cancellationToken);