这种方式接受各种参数,才能使用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(); }
时间: 2024-10-12 10:40:36