Exemplo n.º 1
0
        public PageList <TEntity> GetOrderPagedList(Expression <Func <TEntity, bool> > Condition, PageQueryParam Param)
        {
            var property       = typeof(TEntity).GetProperty(Param.OrderFiled);
            var parameter      = Expression.Parameter(typeof(TEntity), "p");
            var propertyAccess = Expression.MakeMemberAccess(parameter, property);
            var orderByExp     = Expression.Lambda(propertyAccess, parameter);
            var query          = DbContext.Set <TEntity>().Where(Condition);

            string methodName = Param.IsDesc ? "OrderByDescending" : "OrderBy";
            MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName, new Type[] { typeof(TEntity), property.PropertyType }, query.Expression, Expression.Quote(orderByExp));

            query = query.Provider.CreateQuery <TEntity>(resultExp);

            var result = query.AsEnumerable().ToPagedList(Param.PageIndex, Param.PageSize);

            Param.Count = result.TotalItemCount;

            return(result);
        }
Exemplo n.º 2
0
        public PageList <TEntity> GetPagedList(Expression <Func <TEntity, bool> > predicate, PageQueryParam condition, OrderCallBack <TEntity> CallBack)
        {
            IQueryable <TEntity> query = DbContext.Set <TEntity>().Where(predicate);

            query = CallBack(query);

            var result = query.AsEnumerable().ToPagedList(condition.PageIndex, condition.PageSize);

            condition.Count = result.TotalItemCount;

            return(result);
        }
Exemplo n.º 3
0
        public IQueryable <TEntity> QueryPagedList(Expression <Func <TEntity, bool> > predicate, PageQueryParam condition, OrderCallBack <TEntity> CallBack)
        {
            IQueryable <TEntity> query = DbContext.Set <TEntity>().Where(predicate);

            query = CallBack(query);

            int totalCount = 0;
            var queryList  = query.ToPagedList(condition.PageIndex, condition.PageSize, out totalCount);

            return(queryList);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据条件获取分页列表
        /// </summary>
        /// <param name="predicate">查询条件表达式</param>
        /// <param name="condition">条件</param>
        /// <returns>实体分页列表</returns>
        public PageList <TEntity> GetPagedList(Expression <Func <TEntity, bool> > predicate, PageQueryParam condition)
        {
            IQueryable <TEntity> query = DbContext.Set <TEntity>().Where(predicate);

            if (!String.IsNullOrEmpty(condition.OrderFiled))
            {
                query = query.OrderBy(condition.OrderFiled);
            }

            var result = query.AsEnumerable().ToPagedList(condition.PageIndex, condition.PageSize);

            condition.Count = result.TotalItemCount;

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据条件获取分页列表
        /// </summary>
        /// <param name="predicate">查询条件表达式</param>
        /// <param name="condition">条件</param>
        /// <returns>实体分页列表</returns>
        public IQueryable <TEntity> QueryPagedList(Expression <Func <TEntity, bool> > predicate, PageQueryParam condition)
        {
            IQueryable <TEntity> query = DbContext.Set <TEntity>().Where(predicate);

            if (!String.IsNullOrEmpty(condition.OrderFiled))
            {
                query = query.OrderBy(condition.OrderFiled);
                query = query.OrderByDescending(t => condition.OrderFiled);
            }

            int totalCount = 0;
            var queryList  = query.ToPagedList(condition.PageIndex, condition.PageSize, out totalCount);

            return(queryList);
        }