以下是我的代码片段:
Expression<Func<T_ZhaoBiaoInfo,bool>> whereExpr = PredicateExtensions.True<T_ZhaoBiaoInfo>(); if (!string.IsNullOrEmpty(category)) { whereExpr = whereExpr.And(t => t.Category == category); } if (!string.IsNullOrEmpty(region)) { whereExpr = whereExpr.And(t => t.Region == region); } if (DateTime.TryParse(bcreatedt, out beginCreateDt)) { whereExpr = whereExpr.And(t => t.CreateDateTime >= beginCreateDt); } if (DateTime.TryParse(ecreatedt, out endCreateDt)) { whereExpr = whereExpr.And(t => t.CreateDateTime <= endCreateDt); } if (!string.IsNullOrEmpty(zbNo)) { whereExpr = whereExpr.And(t => t.ZBNo == zbNo); } ZhaoBiaoService zhaoBiaoService = new ZhaoBiaoService(); var zhaoBiaoInfoList = zhaoBiaoService.FindListByPage(whereExpr, t => new { t.ZBNo, t.Title, t.CreateDateTime, t.Region, t.Category, t.StartDateTime, t.EndDateTime }, t => t.CreateDateTime, 1, aspNetPager.PageSize, pageNo, out recordCount); 以下是调用的分页方法: public IEnumerable<TResult> FindListByPage<TResult, TKey>(Expression<Func<T, bool>> whereExpr, Expression<Func<T, TResult>> selectExpr, Expression<Func<TResult, TKey>> orderbyExpr, int orderDirection, int pageSize, int pageNo, out int recordCount) { recordCount = 0; var result = zbEntities.CreateObjectSet<T>().Where(whereExpr).Select(selectExpr); if (result == null) return null; recordCount = result.Count(); if (pageNo > recordCount) pageNo = recordCount; if (pageNo <= 0) pageNo = 1; if (recordCount > 0) { if (recordCount > pageSize) { if (orderDirection > 0) { return result.OrderByDescending(orderbyExpr).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList(); } else { return result.OrderBy(orderbyExpr).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList(); } } else { if (orderDirection > 0) { return result.OrderByDescending(orderbyExpr).ToList(); } else { return result.OrderBy(orderbyExpr).ToList(); } } } return null; }
网上有很多的解决方案,但都不能解决我这个问题,我也不知道如何处理,之前一直用得好好的,现在就是不行,麻烦大家帮忙分析一下,找出问题原因,谢谢!