From ef340d4ab12b020fca138c340f92b13106268b01 Mon Sep 17 00:00:00 2001 From: AlexLEWIS Date: Wed, 11 Aug 2021 11:33:48 +0800 Subject: [PATCH] Updated Update Data (markdown) --- Update-Data.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Update-Data.md b/Update-Data.md index 992d921..bff9137 100644 --- a/Update-Data.md +++ b/Update-Data.md @@ -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. -乐观锁的原理,是利用实体某字段,如: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 @@ -213,15 +213,15 @@ var user = fsql.Select() //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 SELECT ... FROM [User] a With(UpdLock, RowLock, NoWait) ``` -## 9、ISelect.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 fsql.Select().Where(a => a.Options.xxx == 1) @@ -229,7 +229,7 @@ fsql.Select().Where(a => a.Options.xxx == 1) .Set(a => a.Title, "111") .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 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 - [《数据库事务》](%e4%ba%8b%e5%8a%a1) -- [《学习FreeSql之一:添加数据》](%e6%b7%bb%e5%8a%a0) -- [《学习FreeSql之二:删除数据》](%e5%88%a0%e9%99%a4) -- [《学习FreeSql之三:查询数据》](%e6%9f%a5%e8%af%a2) -- [《仓储层Repository》](Repository) -- [《过滤器、全局过滤器》](%e8%bf%87%e6%bb%a4%e5%99%a8) -- [《UnitOfWork》](%e5%b7%a5%e4%bd%9c%e5%8d%95%e5%85%83) +- [《FreeSql 101, Part 1: Insert Data》](Insert-Data) +- [《FreeSql 101, Part 2: Delete Data》](Delete-Data) +- [《FreeSql 101, Part 4: Query Data》](Query-Data) +- [《Repository Layer》](Repository-Layer) +- [《Filters and Global Filters》](Filters-and-Global-Filters) +- [《UnitOfWork》](Unit-of-Work) # API