-
Notifications
You must be signed in to change notification settings - Fork 1.3k
1.3 Query‐Page
果糖网 edited this page Jun 23, 2024
·
2 revisions
.ToPageList(pagenumber, pageSize)// Count is not returned
.ToPageList(pagenumber, pageSize, ref totalCount)// Returns Count
.ToPageList(pagenumber, pageSize, ref totalCount,ref totalPage)// Returns Count+ total pages
//Do not consider the lower version can be used
.ToOffsetPage(pagenumber, pageSize, ref totalCount,ref totalPage)
// If the database version is newer, use ToOffsetPage instead of ToPageList
//ToPageList supports an earlier version of the database
// Note that ToPagedList with d is not sqlsugar encapsulated
int pagenumber= 1; // pagenumber starts at 1, not zero
int pageSize = 20;
int totalCount=0;
// Single table paging
var page = db.Queryable<Student>().ToPageList(pagenumber, pageSize, ref totalCount);
// If SqlServer does not want Rownumber, you can use the newer version of ToOffsetPage to support it
// Multi-table paging
var list = db.Queryable<Student>().LeftJoin<School>((st,sc)=>st.SchoolId==sc.Id)
.Select((st,sc)=>new{Id=st.Id,Name=st.Name,SchoolName=sc.Name})
.ToPageList(pageIndex, pageSize, ref totalCount);
RefAsync<int> total = 0; //REF and OUT do not support asynchronous, so this is the best solution for true asynchronous
Db.Queryable<Order>().ToPageListAsync(pagenumber, pageSize, total); //ToPageAsync
Different databases vary
SELECT * FROM
(SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER()
OVER(ORDER BY GetDate())AS RowIndex FROM [STudent]) T
WHERE RowIndex BETWEEN 1 AND 20