【问题标题】:SqlKata - I'm not understanding how Paginate worksSqlKata - 我不明白 Paginate 是如何工作的
【发布时间】:2018-11-26 15:59:33
【问题描述】:

我是使用这个库 SqlKata 的初学者,我很难理解 Paginate 方法的功能。

使用 Get 方法,我可以访问 SQL 记录。但是使用 Paginate 我不能。 Paginate 方法会给我带来数据库的记录吗?

dim db = new QueryFactory(new SqlConnection("[connection-string]"), new SqlServerCompiler())
dim library = db.Query("my_table").Select("*").Paginate(1, 10)
for each book in library.each
    response.write(book.id)
next

这会引发错误:

未找到类型“PaginationResult(Of Object)”上的公共成员“id”。

系统信息:

SqlKata 1.1.3

Microsoft .NET 框架版本:4.0.30319; ASP.NET 版本:4.7.3163.0

VB.NET

【问题讨论】:

  • What is the content of query my_table, id 可能未在您的查询中选择。
  • @Aria 我选择了所有列,正如您在db.Query("my_table").Select("*") 中看到的那样。如果我使用 `db.Query("my_table").Get() 我可以得到 id。我认为这不是 Query 的问题,而是如何处理这个 PaginationResult 的问题。

标签: asp.net vb.net sqlkata


【解决方案1】:

文档似乎需要更新。

这是我设法使用分页的方法:

dim db = new QueryFactory(new SqlConnection("[connection-string]"), new SqlServerCompiler())

dim q = db.Query("my_table")

'Just if you need to know total of pages and other utilities
dim info = q.Paginate(1, 10)

'DB rows
for each book in info.list
    response.write(book.id)
next

'If you do not need the pagination object, you can use:

'here we retrieve 10 records from page 2
for each book in q.ForPage(2, 10).Get()
    response.write(book.id)
next

【讨论】:

    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2012-02-07
    • 2011-02-16
    相关资源
    最近更新 更多