FreeSql (十六)分頁查詢

2022-01-13 05:20:23 字數 1517 閱讀 9569

static ifreesql fsql = new freesql.freesqlbuilder()

.useconnectionstring(freesql.datatype.mysql, "data source=127.0.0.1;port=3306;user id=root;password=root;initial catalog=cccddd;charset=utf8;sslmode=none;max pool size=10")

.build(); //請務必定義成 singleton 單例模式

class topic

public string title

public int clicks

public datetime createtime

public int categoryid

}

var list = fsql.select()

.where(a => a.id > 10)

.count(out var total) //總記錄數量

.page(1, 20)

.tolist();

sqlserver 2012 以前的版本,使用 row_number 分頁;

sqlserver 2012+ 版本,使用最新的 fetch next rows 分頁;

返回前10條記錄:select.take(10).tolist();

跳過前10條記錄,返回記錄:select.offset(10).tolist();

方法返回值

引數描述

tosql

string

返回即將執行的sql語句

tolist

list

執行sql查詢,返回 t1 實體所有欄位的記錄,若存在導航屬性則一起查詢返回,記錄不存在時返回 count 為 0 的列表

tolist

list

lambda

執行sql查詢,返回指定欄位的記錄,記錄不存在時返回 count 為 0 的列表

tolist

list

string field

執行sql查詢,返回 field 指定欄位的記錄,並以元組或基礎型別(int,string,long)接收,記錄不存在時返回 count 為 0 的列表

【分頁】

count

long

查詢的記錄數量

count

out long

查詢的記錄數量,以引數out形式返回

skip

int offset

查詢向後偏移行數

offset

int offset

查詢向後偏移行數

limit

int limit

查詢多少條資料

take

int limit

查詢多少條資料

page

int pageindex, int pagesize

分頁

FreeSql (十)更新資料

freesql提供豐富的資料庫更新功能,支援單條或批量更新,在特定的資料庫執行還可以返回更新後的記錄。static ifreesql fsql new freesql.freesqlbuilder useconnectionstring freesql.datatype.mysql,connecti...

FreeSql (五)插入資料

var connectionstring data source 127.0.0.1 port 3306 user id root password root initial catalog cccddd charset utf8 sslmode none max pool size 10 stat...

FreeSql學習筆記 1 入門

學習過程中,使用的是.net 5 webapi專案,資料庫使用的是sql server,主要會整理下常用的api,現在就開始吧 先選擇乙個webcoreapi專案進行建立,建立完專案後就該引入freesql了 首先引入freesql,根據官方文件的說法得引入乙個freesql包和乙個資料庫驅動,驅動...