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); }
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); }
/// <summary>TODO The aa.</summary> public void Aa() { var client = new MongoClient("mongodb://*****:*****@"http://stackoverflow.com/documentation/mongodb-csharp", VisitPageIndex = 4 }, new Pages { Url = @"https://github.com/", VisitPageIndex = 2 } } }; collection.InsertOne(newItem); var result = IMongoCollectionExtensions.AsQueryable(collection).FirstOrDefault(s => s.SiteName == "Example"); var update = Builders <Interactions> .Update.Set(s => s.SiteName, "New Example"); IMongoCollectionExtensions.FindOneAndUpdate(collection, s => s.SiteName == "Example", update); IMongoCollectionExtensions.DeleteOne(collection, s => s.SiteName == "New Example"); /* * from mongo driver * var result = Group(x => x.A, g => new RootView { Property = g.Key, Field = g.First().B }); * result.Projection.Should().Be("{ _id: \"$A\", Field: { \"$first\" : \"$B\" } }" * * var result2 = IAggregateFluentExtensions.Unwind(IMongoCollectionExtensions.Aggregate(collection), e => e.Pages) * .Group<Pages>(p => p.Pages.url, e => new Pages { Url = e.Key, VisitPageIndex = e.Count() }); * * // var resurt = collection.Aggregate<BsonDocument>().Unwind<BsonDocument>(unwind) */ }
public IMongoQueryable <T> Query() { return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection)); }
public T Find(Expression <Func <T, bool> > where) { return(MongoQueryable.Where <T>(IMongoCollectionExtensions.AsQueryable <T>(this.Collection), where).FirstOrDefault <T>()); }
public long Count(Expression <Func <T, bool> > query) { return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection).LongCount <T>(query)); }
public long Count() { return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection).LongCount <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>()); }
public IList <T> All() { return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection).ToList <T>()); }