码迷,mamicode.com
首页 > 其他好文 > 详细

甩掉分页控件,用Lambda写分页

时间:2014-11-21 12:12:57      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:des   分页控件   style   blog   io   ar   color   使用   sp   

这种方式接受各种参数,才能使用Lambda表达式。

int totalCount;
            var modellist = query.GetList<VideoContent>(e => e.Status != DomainStatue.DELETE 
                && (d.Id > 0 ? e.Id == d.Id : true)
                && (d.Status.HasValue ? e.Status == (DomainStatue)d.Status.Value : true)
                && (d.Title != null ? e.Title.IndexOf(d.Title) > -1 : true)
                && (d.Author != null ? e.Author==d.Author : true) 
                && (d.Hit > 0 ? e.Hit >= d.Hit : true)
                && (d.MentID.HasValue ? e.MentID == d.MentID.Value : true)
                && ((d.Begin_CreateTime.HasValue && d.End_CreateTime.HasValue) ? (e.CreateTime >= d.Begin_CreateTime && e.CreateTime < d.End_CreateTime) : true)
                , es => es.OrderByDescending(e => e.Id), pager.PageIndex, pager.PageSize, out totalCount);

使用泛型可接受任意类

public IEnumerable<T> GetList<T>(Expression<Func<T, bool>> predicate, Func<IQueryable<T>, IQueryable<T>> order, int index, int size) where T : class
        {
            return order(UnitOfWork.Query<T>().Where(predicate)).Skip(Math.Max(0, index - 1) * size).Take(size).ToList();
        }

 

甩掉分页控件,用Lambda写分页

标签:des   分页控件   style   blog   io   ar   color   使用   sp   

原文地址:http://www.cnblogs.com/aigomayi/p/4112187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!