"paging entity framework core" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "paging entity framework core" answered properly. Developers are finding an appropriate answer about paging entity framework core related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like paging entity framework core. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on paging entity framework core.
how manage pagination ef core
public static class PaginationService
{
public static async Task<Pagination<T>> GetPagination<T>(IQueryable<T> query, int page, string orderBy, bool orderByDesc, int pageSize) where T : class
{
Pagination<T> pagination = new Pagination<T>
{
TotalItems = query.Count(),
PageSize = pageSize,
CurrentPage = page,
OrderBy = orderBy,
OrderByDesc = orderByDesc
};
int skip = (page - 1) * pageSize;
var props = typeof(T).GetProperties();
var orderByProperty = props.FirstOrDefault(n => n.GetCustomAttribute<SortableAttribute>()?.OrderBy == orderBy);
if (orderByProperty == null)
{
throw new Exception($"Field: '{orderBy}' is not sortable");
}
if (orderByDesc)
{
pagination.Result = await query
.OrderByDescending(x => orderByProperty.GetValue(x))
.Skip(skip)
.Take(pageSize)
.ToListAsync();
return pagination;
}
pagination.Result = await query
.OrderBy(x => orderByProperty.GetValue(x))
.Skip(skip)
.Take(pageSize)
.ToListAsync();
return pagination;
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on paging entity framework core can get a collection of related answers to their query. Programmers need to enter their query on paging entity framework core related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about paging entity framework core for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of paging entity framework core while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "paging entity framework core". Visit this developer's friendly online web community, CodeProZone, and get your queries like paging entity framework core resolved professionally and stay updated to the latest Whatever updates.