public Pagination <T> Query(int index, int pagecount, Expression <Func <T, bool> > query) { using (MVCBlogContext Context = new MVCBlogContext()) { var ids = query != null?Context.Set <T>().Where(query).OrderByDescending(x => x.Id).Select(x => x.Id).ToPagedList(index, pagecount) : Context.Set <T>().OrderByDescending(x => x.Id).Select(x => x.Id).ToPagedList(index, pagecount); if (ids != null && ids.Count > 0) { Pagination <T> pagination = new Pagination <T>() { Items = GetByIds(ids), TotalItemCount = ids.TotalItemCount, PageCount = ids.PageCount, PageNumber = ids.PageNumber, PageSize = ids.PageSize }; return(pagination); } else { return(new Pagination <T>() { Items = null, TotalItemCount = 0, PageCount = 0, PageNumber = index, PageSize = pagecount }); } } }
public IEnumerable <T> Query(Expression <Func <T, bool> > query) { using (MVCBlogContext Context = new MVCBlogContext()) { var ids = query != null?Context.Set <T>().Where(query).OrderByDescending(x => x.Id).Select(x => x.Id).ToList() : Context.Set <T>().OrderByDescending(x => x.Id).Select(x => x.Id).ToList(); if (ids != null && ids.Count > 0) { return(GetByIds(ids)); } else { return(new List <T>()); } } }
// public abstract T GetById(int id); public virtual T GetFromDB(int id) { MVCBlogContext Context = new MVCBlogContext(); return(Context.Set <T>().Find(id)); }