Updated Insert or Update (markdown)

AlexLEWIS
2021-08-17 22:29:02 +08:00
parent d0846348fc
commit 4bf001417e

@@ -98,9 +98,9 @@ Note: This operation is only valid for the variable `cts`, not for comparison an
## 4. `On Duplicate Key Update` (MySql only)
FreeSql.Provider.MySqlFreeSql.Provider.MySqlConnector 支持 MySql 特有的功能,On Duplicate Key Update
`FreeSql.Provider.MySql` and `FreeSql.Provider.MySqlConnector` support MySql's unique function `On Duplicate Key Update`.
这个功能也可以实现插入或更新数据,并且支持批量操作。
This function can also insert or update data, and supports batch operations.
```csharp
class TestOnDuplicateKeyUpdateInfo {
@@ -120,20 +120,20 @@ fsql.Insert(item)
//`time` = VALUES(`time`)
```
OnDuplicateKeyUpdate() 之后可以调用的方法:
Methods that can be called after `OnDuplicateKeyUpdate()`:
| 方法名 | 描述 |
| Method | Description |
| -- | -- |
| IgnoreColumns | 忽略更新的列,机制和 IUpdate.IgnoreColumns 一样 |
| UpdateColumns | 指定更新的列,机制和 IUpdate.UpdateColumns 一样 |
| Set | 手工指定更新的列,与 IUpdate.Set 功能一样 |
| SetRaw | 作为 Set 方法的补充,可传入 SQL 字符串 |
| ToSql | 返回即将执行的 SQL 语句 |
| ExecuteAffrows | 执行,返回影响的行数 |
| IgnoreColumns | Ignore updated columns, the mechanism is the same as `IUpdate.IgnoreColumns` |
| UpdateColumns | Specify updated columns, the mechanism is the same as `IUpdate.UpdateColumns` |
| Set | Manually specify the updated column, the same function as `IUpdate.Set` |
| SetRaw | As a supplement to the `Set` method, SQL strings can be passed in. |
| ToSql | Return the SQL statement to be executed |
| ExecuteAffrows | Execute and return the number of rows affected |
IInsert 与 OnDuplicateKeyUpdate 都有 IgnoreColumnsUpdateColumns 方法。
Both `IInsert` and `OnDuplicateKeyUpdate` have `IgnoreColumns` and `UpdateColumns` methods.
当插入实体/集合实体的时候,忽略了 time 列,代码如下:
When inserting an entity or a set of entities, the `time` column is ignored, the code is as follows:
```csharp
fsql.Insert(item)
@@ -146,19 +146,19 @@ fsql.Insert(item)
//`time` = '2000-01-01 00:00:00.000'
```
我们发现UPDATE time 部分变成了常量,而不是 VALUES(\`time\`),机制如下:
We found that the `UPDATE time` part became a constant instead of **VALUES(\`time\`)**. The mechanism is as follows:
当 insert 部分中存在的列,在 update 中将以 VALUES(\`字段\`) 的形式设置;
When there are columns in the `insert` part, they will be set in the form of VALUES(\`field\`) in the `update`;
当 insert 部分中不存在的列,在 update 中将为常量形式设置,当操作实体数组的时候,此常量为 case when ... end 执行(与 IUpdate 一样);
When a column that does not exist in the `insert` part, it will be set as a constant in the `update`. When manipulating the entity array, this constant is executed for `case when ... end` (same as `IUpdate`);
---
## 5. `On Conflict Do Update` (PostgreSQL only)
FreeSql.Provider.PostgreSQL 支持 PostgreSQL 9.5+ 特有的功能,On Conflict(id) Do Update
`FreeSql.Provider.PostgreSQL` supports PostgreSQL 9.5+ unique function `On Conflict(id) Do Update`.
使用方法 MySql OnDuplicateKeyUpdate 大致相同。
The usage method is roughly the same as that of MySql's `OnDuplicateKeyUpdate`.
```csharp
class TestOnConflictDoUpdateInfo {