mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-04 23:40:53 +08:00
update
@@ -183,14 +183,11 @@ fsql.Ado.CommandFluent($"{sql1} UNION ALL {sql2}")
|
||||
.ExecuteDataTable();
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Paging Problem
|
||||
|
||||
After using `UNION ALL`, there will be a problem if you paginate directly. Please see the specific example:
|
||||
|
||||
|
||||
### There is a problem with using WithSql + Page multiple times: There is a paging statement in each WithSql
|
||||
There is a problem with using WithSql + Page multiple times: There is a paging statement in each WithSql
|
||||
|
||||
```csharp
|
||||
var sql1 = fsql.Select<Topic>()
|
||||
|
||||
10
withsql.md
10
withsql.md
@@ -187,13 +187,12 @@ fsql.Ado.CommandFluent($"{sql1} UNION ALL {sql2}")
|
||||
.ExecuteDataTable();
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 分页问题
|
||||
|
||||
Union All 之后 如果直接 分页会有一个问题。请看具体示例
|
||||
|
||||
多次 WithSql + Page 存在问题:每个WithSql内都有一个Page分页
|
||||
|
||||
### 多次WithSql+Page存在问题:每个WithSql内都有一个Page分页
|
||||
```csharp
|
||||
var sql1 = fsql.Select<Topic>()
|
||||
.Where(a => a.Title.Contains("xxx"))
|
||||
@@ -230,7 +229,8 @@ WithSql 可以和 AsTable 实现分表的功能。
|
||||
|
||||
## 解决方案
|
||||
|
||||
### 多次withsql,如需分页,需要按下面的二步操作
|
||||
多次 withsql ,如需分页,需要按下面的二步操作
|
||||
|
||||
- 第一步:通过witsql,将二个sql组成一个sql。
|
||||
|
||||
```csharp
|
||||
@@ -253,12 +253,14 @@ WithSql 可以和 AsTable 实现分表的功能。
|
||||
```
|
||||
|
||||
- 第二步:之后 调用 Page 则是通过 Union ALL 后的结果上分页
|
||||
|
||||
```csharp
|
||||
var sql2 = g.mysql.Select<Topic>()
|
||||
.WithSql(sql)
|
||||
.Page(2, 10)
|
||||
.ToSql();
|
||||
```
|
||||
|
||||
```sql
|
||||
SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime`
|
||||
FROM ( SELECT * from (SELECT *
|
||||
|
||||
Reference in New Issue
Block a user