public async Task DeleteManyAsync(Expression <Func <TEntity, bool> > predicate, bool autoSave = false, CancellationToken cancellationToken = default) { var entities = await MongoQueryable.Where((await GetMongoQueryableAsync(cancellationToken)), predicate) .ToListAsync(cancellationToken); await DeleteManyAsync(entities, autoSave, cancellationToken); }
public async Task <List <TEntity> > GetListAsync(Expression <Func <TEntity, bool> > predicate, bool includeDetails = true, CancellationToken cancellationToken = default) { var query = await GetMongoQueryableAsync(cancellationToken); return(await MongoQueryable.Where(query, predicate) .ToListAsync(cancellationToken)); }
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> Where <T>(this IQueryable <T> queryable, Expression <Func <T, bool> > filter) { if (queryable is IMongoQueryable <T> mongoQueryable) { return(MongoQueryable.Where(mongoQueryable, filter)); } return(Queryable.Where(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 IMongoQueryable <T> Query(params Expression <Func <T, bool> >[] where) { IMongoQueryable <T> _query = this.Query(); if (where.Count <Expression <Func <T, bool> > >() > 0) { Expression <Func <T, bool> >[] expressionArray = where; for (int i = 0; i < (int)expressionArray.Length; i++) { _query = MongoQueryable.Where <T>(_query, expressionArray[i]); } } return(_query); }
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 T Find(Expression <Func <T, bool> > where) { return(MongoQueryable.Where <T>(IMongoCollectionExtensions.AsQueryable <T>(this.Collection), where).FirstOrDefault <T>()); }
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>()); }