Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        /// <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)
             */
        }
Esempio n. 6
0
 public IMongoQueryable <T> Query()
 {
     return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection));
 }
Esempio n. 7
0
 public T Find(Expression <Func <T, bool> > where)
 {
     return(MongoQueryable.Where <T>(IMongoCollectionExtensions.AsQueryable <T>(this.Collection), where).FirstOrDefault <T>());
 }
Esempio n. 8
0
 public long Count(Expression <Func <T, bool> > query)
 {
     return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection).LongCount <T>(query));
 }
Esempio n. 9
0
 public long Count()
 {
     return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection).LongCount <T>());
 }
Esempio n. 10
0
        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()));
        }
Esempio n. 11
0
 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>());
 }
Esempio n. 12
0
 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>());
 }
Esempio n. 13
0
 public IList <T> All()
 {
     return(IMongoCollectionExtensions.AsQueryable <T>(this.Collection).ToList <T>());
 }