"paging entity framework core" Code Answer's
You're definitely familiar with the best coding language C# 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 C# coding language. By visiting this online portal developers get answers concerning C# codes question like paging entity framework core. Enter your desired code related query in the search bar and get every piece of information about C# code related question on paging entity framework core.
paging entity framework core

public abstract class PagedResultBase
{
public int CurrentPage { get; set; }
public int PageCount { get; set; }
public int PageSize { get; set; }
public int RowCount { get; set; }
public int FirstRowOnPage
{
get { return (CurrentPage - 1) * PageSize + 1; }
}
public int LastRowOnPage
{
get { return Math.Min(CurrentPage * PageSize, RowCount); }
}
}
public class PagedResult<T> : PagedResultBase where T : class
{
public IList<T> Results { get; set; }
public PagedResult()
{
Results = new List<T>();
}
}
Source: www.codingame.com
paging entity framework core

public static PagedResult<T> GetPaged<T>(this IQueryable<T> query,
int page, int pageSize) where T : class
{
var result = new PagedResult<T>();
result.CurrentPage = page;
result.PageSize = pageSize;
result.RowCount = query.Count();
var pageCount = (double)result.RowCount / pageSize;
result.PageCount = (int)Math.Ceiling(pageCount);
var skip = (page - 1) * pageSize;
result.Results = query.Skip(skip).Take(pageSize).ToList();
return result;
}
Source: www.codingame.com
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
how manage pagination ef core

[HttpGet]
public async Task<IActionResult> GetUsers([FromQuery] string orderBy, [FromQuery] bool orderByDesc, [FromQuery] int page, [FromQuery] int size)
{
var query = _context.User.AsQueryable();
try
{
var list = await PaginationService.GetPagination(query, page, orderBy, orderByDesc, size);
return new JsonResult(list);
}
catch (Exception e)
{
return new BadRequestObjectResult(e.Message);
}
}
Source: stackoverflow.com
All those coders who are working on the C# 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 C# 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 C# code while coding their module. Coders are also allowed to rectify already present answers of paging entity framework core while working on the C# 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 C# updates.