예제 #1
0
        /// <summary>
        /// 从全量数据生成分页数据
        /// </summary>
        /// <param name="source">源数据</param>
        /// <param name="para">分页数据</param>
        /// <returns>分页后的数据</returns>
        public static DataResult <T> ToODataResult <T>(this IQueryable <T> source, IODataParameter para)
        {
            Checker.NotNull(source, nameof(source));
            Checker.CheckODataParameter(para, nameof(para));
            int count = 0;

            if (para.Count)
            {
                count = source.Count();
            }
            IList <T> result;

            if (para == null)
            {
                result = source.ToList();
            }
            else
            {
                var orders = para.GetOrderings();
                result = ODataQuery(source, para.Top, para.Skip, orders).ToList();
            }
            return(new DataResult <T>()
            {
                Count = count, Result = result,
            });
        }
예제 #2
0
        /// <summary>
        /// OData查询,支持 top, skip, orderby
        /// </summary>
        /// <typeparam name="T">数据源类型</typeparam>
        /// <param name="query">数据源</param>
        /// <param name="para">OData参数</param>
        /// <returns></returns>
        public static IQueryable <T> ODataQuery <T>(this IQueryable <T> query, IODataParameter para)
        {
            Checker.NotNull(query, nameof(query));
            Checker.CheckODataParameter(para, nameof(para));
            var orders = para.GetOrderings();

            return(ODataQuery(query, para.Top, para.Skip, orders));
        }