Ejemplo n.º 1
0
        public static IMongoQueryable <TSource> MongoQueryOptionsAsQueryable <TSource>(
            this IMongoQueryable <TSource> source,
            IQueryOptions queryOptions)
        {
            // Is there any sort column supplied?
            IMongoQueryable <TSource> data = source;

            if (!string.IsNullOrEmpty(queryOptions.Sort))
            {
                data = data.OrderByName(queryOptions.Sort, queryOptions.SortOrder == SortOrder.Descending);
            }

            if (queryOptions.PageSize > 0 || queryOptions.RecordCount > 0)
            {
                // Apply paging to (sorted) data
                data = queryOptions.RecordCount > 0
                    ? data.Skip(queryOptions.StartRecord).Take(queryOptions.RecordCount)
                    : data.Skip((queryOptions.Page - 1) * queryOptions.PageSize).Take(queryOptions.PageSize);
            }

            return(data);
        }