Exemple #1
0
        /// <summary>
        /// 获取当前集合分页列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortInfo"></param>
        /// <param name="predicate"></param>
        /// <param name="tracking"></param>
        /// <returns></returns>
        protected PagedList <T> GetPagedList <T>(int page, int pageSize, SortInfo sortInfo, Expression <Func <T, bool> > predicate = null, bool tracking = false)
            where T : class
        {
            return(this.Queryable <T, PagedList <T> >(query =>
            {
                //排序
                query = query.OrderBy(sortInfo.Column, sortInfo.Ascending);
                //筛选条件
                if (predicate != null)
                {
                    query = query.Where(predicate);
                }

                return new PagedList <T>
                {
                    RowSet = query.Skip((page - 1) * pageSize).Take(pageSize).ToList(),
                    Count = query.Count()
                };
            }, tracking));
        }
Exemple #2
0
        /// <summary>
        /// 解析并生成排序语句
        /// 若解析失败则返回默认排序信息
        /// </summary>
        /// <param name="orderBy">>格式为:field_(DESC/ASC)</param>
        /// <param name="defaultSort"></param>
        /// <param name="includeSortableColumns">允许排序的字段信息集合</param>
        /// <returns></returns>
        protected SortInfo GetSortInfo(string orderBy, SortInfo defaultSort, IEnumerable <AliasColumn> includeSortableColumns = null)
        {
            var sortInfo = SortInfo.Parse(orderBy);

            if (sortInfo == null)
            {
                sortInfo = defaultSort;
            }
            else
            {
                var column = includeSortableColumns.SingleOrDefault(i => i.Column == sortInfo.Column);
                if (column == null)
                {
                    throw new ArgumentException("无效的排序字符串");
                }
                //判断排序字段是否有别名若有则转换为含有别名的字段
                if (!string.IsNullOrEmpty(column.Alias))
                {
                    sortInfo.Column = column.ToString();
                }
            }

            return(sortInfo);
        }
Exemple #3
0
        /// <summary>
        /// 获取当前集合列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate">查询表达式</param>
        /// <param name="sortInfo">排序信息</param>
        /// <param name="tracking"></param>
        /// <returns></returns>
        protected IEnumerable <T> GetList <T>(Expression <Func <T, bool> > predicate = null, SortInfo sortInfo = null, bool tracking = false)
            where T : class
        {
            return(this.Queryable <T, IEnumerable <T> >(query =>
            {
                //排序
                if (sortInfo != null)
                {
                    query = query.OrderBy(sortInfo.Column, sortInfo.Ascending);
                }
                //筛选条件
                if (predicate != null)
                {
                    query = query.Where(predicate);
                }

                return query.ToList();
            }, tracking));
        }