Updated With Sql (markdown)

AlexLEWIS
2021-09-27 13:45:26 +08:00
parent f4b63c5fb2
commit 4aa9c765dd

@@ -118,11 +118,11 @@ SELECT ID, Age
``` ```
## 通过 WithSql+ ToSQL实现 Union ALL 查询方法 ## WithSql+ ToSQL = Union ALL
### 1、二次 ISelect 查询WithSql 使用多次,等于 UNION ALL 查询 ### Two-Stage ISelect Query: Use WithSql Multiple Times to Convert to UNION ALL Query
WithSql 使用多次为 UNION ALL 查询,所以我们可以利用 ISelect.ToSql(FieldAliasOptions.AsProperty) 得到生成的 SQL如下 After using `WithSql` multiple times, a query statement based on `UNION ALL` will be generated. So we can use `ISelect.ToSql(FieldAliasOptions.AsProperty)` to get the generated SQL as follows:
```csharp ```csharp
var sql1 = fsql.Select<Topic>() var sql1 = fsql.Select<Topic>()
@@ -154,9 +154,11 @@ FROM ( SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime`
### 2、跨分表查询AsTable 相同实体多次操作,等于 Union ALL 查询 ### 2、跨分表查询AsTable 相同实体多次操作,等于 Union ALL 查询
### Cross Sub-Table Query: Wse AsTable for the Same Entity Multiple Times to Convert to UNION ALL Query
```c# ```c#
var sql = fsql.Select<User>() var sql = fsql.Select<User>()
.AsTable((type, oldname) => "table_1")a .AsTable((type, oldname) => "table_1")
.AsTable((type, oldname) => "table_2") .AsTable((type, oldname) => "table_2")
.ToSql(a => a.Id); .ToSql(a => a.Id);
``` ```
@@ -167,7 +169,7 @@ UNION ALL
select * from (SELECT a."Id" as1 FROM "table_2" a) ftb select * from (SELECT a."Id" as1 FROM "table_2" a) ftb
``` ```
### 3、利用 ToSql 拼接新的 SQL使用 IAdo 执行 ### Use ToSql to Splice New SQL Statements, And Use IAdo to Execute
```c# ```c#
var sql1 = fsql.Select<Topic>() var sql1 = fsql.Select<Topic>()
@@ -183,8 +185,9 @@ fsql.Ado.CommandFluent($"{sql1} UNION ALL {sql2}")
## 分页问题 ## Paging Problem
Union All 之后 如果直接 分页会有一个问题。请看具体示例
After using `UNION ALL`, there will be a problem if you paginate directly. Please see the specific example:
### 多次WithSql+Page存在问题每个WithSql内都有一个Page分页 ### 多次WithSql+Page存在问题每个WithSql内都有一个Page分页