Exemple #1
0
        public static IQueryable <T> OrderBy <T>(this IQueryable <T> queryable, string propertyName, out int RecordCount, out int PageCount, ref int CurrentPage, int PageSize = 10, bool IsDesc = true, string propertyName2 = "", bool IsDesc2 = true)
        {
            //
            if (PageSize < 1)
            {
                PageSize = 1;
            }
            //
            RecordCount = queryable.Count();//记录总数
            //
            PageCount = (RecordCount + PageSize - 1) / PageSize;
            //设置当前页
            if (CurrentPage < 1)
            {
                CurrentPage = 1;
            }
            if (CurrentPage > PageCount)
            {
                //大于总页数取最大数
                CurrentPage = PageCount;
            }
            if (CurrentPage == 0)
            {
                CurrentPage = 1;
            }
            //
            dynamic keySelector = QueryableHelper <T> .GetLambdaExpression(propertyName);

            //
            return(QueryableHelper <T> .OrderBy(queryable, propertyName, IsDesc, propertyName2, IsDesc2).Skip((CurrentPage - 1) * PageSize).Take(PageSize));
        }
        public static IQueryable <T> OrderBy <T>(this IQueryable <T> queryable, params string[] orderbyArray)
        {
            IOrderedQueryable <T> result = null;

            foreach (string prop in orderbyArray)
            {
                var     tuple       = ParseOrderbyString(prop);
                dynamic keySelector = QueryableHelper <T> .GetLambdaExpression(tuple.Item1);

                if (result == null)
                {
                    result = tuple.Item2
                                 ? Queryable.OrderByDescending(queryable, keySelector)
                                 : Queryable.OrderBy(queryable, keySelector);
                }
                else
                {
                    result = tuple.Item2
                             ? Queryable.ThenByDescending(result, keySelector)
                             : Queryable.ThenBy(result, keySelector);
                }
            }
            return(result);
        }