Updated Update Data (markdown)

AlexLEWIS
2021-08-11 11:33:48 +08:00
parent 05b9d555a3
commit ef340d4ab1

@@ -197,11 +197,11 @@ The three of them are functions of the same level, corresponding to:
When updating the entire entity data, it is very easy to cause the old data to update the new record in the case of concurrency. When updating the entire entity data, it is very easy to cause the old data to update the new record in the case of concurrency.
乐观锁的原理是利用实体某字段long version更新前先查询数据此时 version 为 1更新时产生的 SQL 会附加 where version = 1当修改失败时即 Affrows == 0抛出异常DbUpdateVersionException The principle of optimistic locking: use a certain field of the entity, such as `long version`. Query the data before updating, and then `version` is `1`. The SQL generated during the update will append `where version = 1`, and an exception (DbUpdateVersionException) will be thrown when the modification fails (ie, `Affrows == 0`).
每个实体只支持一个乐观锁属性,在属性前标记特性:[Column(IsVersion = true)] 即可。 Each entity only supports one optimistic lock attribute, mark the attribute before the property: `[Column(IsVersion = true)]`.
> 适用 SetSource 更新,每次更新 version 的值都会增加 1 > Applicable to SetSource update, the value of `version` will increase by `1` each time it is updated.
## 8. Pessimistic Lock ## 8. Pessimistic Lock
@@ -213,15 +213,15 @@ var user = fsql.Select<User>()
//SELECT ... FROM User a for update nowait //SELECT ... FROM User a for update nowait
``` ```
for update 在 Oracle/PostgreSQL/MySql 是通用的写法,我们对 SqlServer 做了特别适配,执行的 SQL 语句大致如下: `ForUpdate` is a common way of writing in Oracle/PostgreSQL/MySql. We have made a special adaptation to SqlServer. The SQL statements executed are roughly as follows:
```sql ```sql
SELECT ... FROM [User] a With(UpdLock, RowLock, NoWait) SELECT ... FROM [User] a With(UpdLock, RowLock, NoWait)
``` ```
## 9ISelect.ToUpdate 高级更新 ## 9. Advanced Update: `ISelect.ToUpdate`
IUpdate 默认不支持导航对象多表关联等。ISelect.ToUpdate 可将查询转为 IUpdate以便使用导航对象更新数据如下 `IUpdate` does not support navigation objects, multi-table association, etc. by default. `ISelect.ToUpdate` can convert the query to `IUpdate` to update the data using the navigation object, as follows:
```csharp ```csharp
fsql.Select<T1>().Where(a => a.Options.xxx == 1) fsql.Select<T1>().Where(a => a.Options.xxx == 1)
@@ -229,7 +229,7 @@ fsql.Select<T1>().Where(a => a.Options.xxx == 1)
.Set(a => a.Title, "111") .Set(a => a.Title, "111")
.ExecuteAffrows(); .ExecuteAffrows();
``` ```
注意:此方法不是将数据查询到内存再更新,上面的代码产生如下 SQL 执行: Note: This method is not to query the data to the memory and then update, the above code produces the following SQL execution:
```sql ```sql
UPDATE `T1` SET Title = '111' WHERE id in (select a.id from T1 a left join Options b on b.t1id = a.id where b.xxx = 1) UPDATE `T1` SET Title = '111' WHERE id in (select a.id from T1 a left join Options b on b.t1id = a.id where b.xxx = 1)
@@ -243,12 +243,12 @@ The benefits of using this program for dang complex update:
## Reference ## Reference
- [《数据库事务》](%e4%ba%8b%e5%8a%a1) - [《数据库事务》](%e4%ba%8b%e5%8a%a1)
- [学习FreeSql之一:添加数据》](%e6%b7%bb%e5%8a%a0) - [《FreeSql 101, Part 1: Insert Data》](Insert-Data)
- [学习FreeSql之二:删除数据》](%e5%88%a0%e9%99%a4) - [《FreeSql 101, Part 2: Delete Data》](Delete-Data)
- [学习FreeSql之三:查询数据》](%e6%9f%a5%e8%af%a2) - [《FreeSql 101, Part 4: Query Data》](Query-Data)
- [仓储层Repository》](Repository) - [《Repository Layer](Repository-Layer)
- [过滤器、全局过滤器》](%e8%bf%87%e6%bb%a4%e5%99%a8) - [Filters and Global Filters》](Filters-and-Global-Filters)
- [《UnitOfWork》](%e5%b7%a5%e4%bd%9c%e5%8d%95%e5%85%83) - [《UnitOfWork》](Unit-of-Work)
# API # API