Skip to content

09.Page

1448376744 edited this page Sep 3, 2019 · 1 revision

1. 通过下标分页查询

using (var context = DbContextFactory.GetDbContext())
{
    var page1 = context.From<User>()
       .Skip(0, 10)
       .Select();
    
    var page2 = context.From<User>()
      .Skip(10, 10)
      .Select();
}

//SELECT id AS Id,is_delete AS IsDelete,balance AS Balance,nick_name AS NickName,create_time AS CreateTime FROM user LIMIT 0,10

//SELECT id AS Id,is_delete AS IsDelete,balance AS Balance,nick_name AS NickName,create_time AS CreateTime FROM user LIMIT 10,10

2. 通过页码分页,并返回总数

using (var context = DbContextFactory.GetDbContext())
{
    var page1 = context.From<User>()
       .Page(1,10,out long total1)
       .Select();
    
    var page2 = context.From<User>()
      .Page(2, 10, out long total2)
      .Select();
}

// SELECT COUNT(1) FROM user
// SELECT id AS Id,is_delete AS IsDelete,balance AS Balance,nick_name AS NickName,create_time AS CreateTime FROM user LIMIT 0,10

// SELECT COUNT(1) FROM user
// SELECT id AS Id,is_delete AS IsDelete,balance AS Balance,nick_name AS NickName,create_time AS CreateTime FROM user LIMIT 10,10
Clone this wiki locally