/// <summary> /// Getting a set of data by given condition. /// </summary> /// <typeparam name="TKey"></typeparam> /// <param name="skipCount"></param> /// <param name="takeCount"></param> /// <param name="filter"></param> /// <param name="sortingExpression"></param> /// <param name="sortDir"></param> /// <param name="includeProperties"></param> /// <returns>List<T></returns> public async Task <List <T> > GetPage <TKey>(int skipCount, int takeCount, Expression <Func <T, bool> > filter, Expression <Func <T, TKey> > sortingExpression, CommonEnum.SortDirection sortDir = CommonEnum.SortDirection.Ascending, string includeProperties = "") { IQueryable <T> query = AppDbContext.Set <T>().Where(filter); query = includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Aggregate(query, (current, includeProperty) => current.Include(includeProperty)); switch (sortDir) { case CommonEnum.SortDirection.Ascending: if (skipCount == 0) { query = query.OrderBy <T, TKey>(sortingExpression).Take(takeCount); } else { query = query.OrderBy <T, TKey>(sortingExpression).Skip(skipCount).Take(takeCount); } break; case CommonEnum.SortDirection.Descending: if (skipCount == 0) { query = query.OrderByDescending <T, TKey>(sortingExpression).Take(takeCount); } else { query = query.OrderByDescending <T, TKey>(sortingExpression).Skip(skipCount).Take(takeCount); } break; default: break; } return(await query.ToListAsync()); }
/// <summary> /// Getting a set of data by given condition. /// </summary> /// <typeparam name="TKey"></typeparam> /// <param name="skipCount"></param> /// <param name="takeCount"></param> /// <param name="filter"></param> /// <param name="sortingExpression"></param> /// <param name="sortDir"></param> /// <param name="includeProperties"></param> /// <returns>List<T></returns> public async Task <List <T> > GetPage <TKey>(int skipCount, int takeCount, Expression <Func <T, bool> > filter, Expression <Func <T, TKey> > sortingExpression, CommonEnum.SortDirection sortDir = CommonEnum.SortDirection.Ascending, string includeProperties = "") { return(await RetrieveRepository.GetPage(skipCount, takeCount, filter, sortingExpression, sortDir, includeProperties)); }