-
Notifications
You must be signed in to change notification settings - Fork 857
Pagination
AlexLEWIS edited this page Aug 10, 2021
·
9 revisions
中文 | English
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, connectionString)
.Build(); //Be sure to define as singleton mode
class Topic {
[Column(IsIdentity = true)]
public int Id { get; set; }
public string Title { get; set; }
public int Clicks { get; set; }
public DateTime CreateTime { get; set; }
public int CategoryId { get; set; }
}
var list = fsql.Select<Topic>()
.Where(a => a.Id > 10)
.Count(out var total) //Total number of records
.Page(1, 20)
.Tolist();
For the previous versions of SqlServer 2012
, use row_number
for pagination;
For SqlServer 2012+
version, using the latest fetch next rows
pagination;
Methods | Return | Parameters | Description |
---|---|---|---|
ToSql | string | Return the SQL statement to be executed | |
ToList | List<T1> | 执行SQL查询,返回 T1 实体所有字段的记录,若存在导航属性则一起查询返回,记录不存在时返回 Count 为 0 的列表 | |
ToList<T> | List<T> | Lambda | 执行SQL查询,返回指定字段的记录,记录不存在时返回 Count 为 0 的列表 |
ToList<T> | List<T> | string field | 执行SQL查询,返回 field 指定字段的记录,并以元组或基础类型(int,string,long)接收,记录不存在时返回 Count 为 0 的列表 |
【Pagination】 | |||
Count | long | Number of records queried | |
Count | <this> | out long | The number of records to be queried, returned in the form of parameter with out
|
Skip | <this> | int offset | Query the number of rows shifted backward |
Offset | <this> | int offset | Query the number of rows shifted backward |
Limit | <this> | int limit | 查询多少条数据 |
Take | <this> | int limit | 查询多少条数据 |
Page | <this> | int pageIndex, int pageSize | 分页 |