public async Task <List <T> > GetPageAsync <TKey>(int PageNumeber, int PageSize, Expression <Func <T, bool> > filter, Expression <Func <T, TKey> > sortingExpression, SortDirection sortDir = SortDirection.Ascending, string includeProperties = "") { IQueryable <T> query = context.Set <T>(); int skipCount = (PageNumeber - 1) * PageSize; if (filter != null) { query = query.Where(filter); } query = includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Aggregate(query, (current, includeProperty) => current.Include(includeProperty)); switch (sortDir) { case SortDirection.Ascending: if (skipCount == 0) { query = query.OrderBy <T, TKey>(sortingExpression).Take(PageSize); } else { query = query.OrderBy <T, TKey>(sortingExpression).Skip(skipCount).Take(PageSize); } break; case SortDirection.Descending: if (skipCount == 0) { query = query.OrderByDescending <T, TKey>(sortingExpression).Take(PageSize); } else { query = query.OrderByDescending <T, TKey>(sortingExpression).Skip(skipCount).Take(PageSize); } break; default: break; } return(await query.AsNoTracking().ToListAsync()); }
/// <summary> /// Initializes a new instance of the <see cref="Repository{T}"/> class. /// </summary> /// <param name="context">The context<see cref="GBSampleContext"/></param> public Repository(GBSampleContext context) { this.context = context; entities = context.Set <T>(); }
public AuthorRepository(GBSampleContext context) : base(context) { entity = context.Set <Author>(); }
public ReviewRepository(GBSampleContext context) : base(context) { entity = context.Set <Review>(); }
public BookRepository(GBSampleContext context) : base(context) { entity = context.Set <Book>(); }