Ejemplo n.º 1
0
        public MongoCursor <BsonDocument> Find(string document, IMongoQuery query, PagerAndSort ps, out long totalCount)
        {
            var source = database.GetCollection(document);

            totalCount = source.Count(query);
            var sortBy = (ps.SortDirction == SortDirction.Asc) ? SortBy.Ascending(ps.SortField) : SortBy.Descending(ps.SortField);

            return(source.FindAll().SetSortOrder(sortBy).SetSkip(ps.PageSize * (ps.PageIndex - 1)).SetLimit(ps.PageSize));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 分页和排序
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="ps">分页和排序</param>
        /// <returns></returns>
        public MongoCursor <T> Find <T>(IMongoQuery query, PagerAndSort ps, out long totalCount)
        {
            var source      = Find <T>(query);
            var sourceCount = source.Clone <T>();

            totalCount = sourceCount.Count();
            var sortBy = SortBy.Descending(ps.SortField);

            if (ps.SortDirction == SortDirction.Asc)
            {
                sortBy = SortBy.Ascending(ps.SortField);
            }
            return(source.SetSortOrder(sortBy).SetSkip(ps.PageSize * (ps.PageIndex - 1)).SetLimit(ps.PageSize));
        }