asp net core with entity framework code example

Example 1: c# .net core entity framework

//ref https://softchris.github.io/pages/dotnet-orm.html#why-orm

Example 2: 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;
}

Tags:

Misc Example