Esempio n. 1
0
        public async static Task <PagedList <TProjection> > ToPagedListAsync <TProjection>(this IAggregateFluent <TProjection> findFluent, int pageNumber, int pageSize)
        {
            var count = await findFluent.AnyAsync() ? findFluent.Group(new BsonDocument
            {
                { "_id", "_id" },
                { "count", new BsonDocument("$sum", 1) }
            })
                        .FirstAsync().Result["count"].AsInt32 : 0;

            var items = await findFluent.Skip(pageSize *(pageNumber - 1))
                        .Limit(pageSize)
                        .ToListAsync();

            return(new PagedList <TProjection>(items, count, pageNumber, pageSize));
        }