update

28810
2019-03-11 17:26:01 +08:00
parent b119da503e
commit 2cf0babfc9
6 changed files with 26 additions and 3 deletions

@@ -1,4 +1,4 @@
FreeSql实现了简单数据库事务方法脏读等事务相关方法未提供。首先不大建议擅自控制事务级别,数据库默认事务已经够用了;再者这些方法各大数据库、甚至引擎的事务级别五花八门难统一强制实现会徒增使用成本这不是FreeSql设计原意最方便的ORM
FreeSql实现了简单数据库事务方法脏读等事务相关方法暂时未提供。主要原因系这些方法各大数据库、甚至引擎的事务级别五花八门难统一。
事务用于处理数据的一致性,处于同一个事务中的操作是一个工作单元,要么全部执行成功,要么全部执行失败。
@@ -45,6 +45,17 @@ fsql.Transaction(() => {
3、fsql.Transaction 有防止死锁机制60秒事务未结束的将会被其他线程强行提交不是回滚可能造成不完整的事务但仔细一想60秒还没完成的事务是什么原因呢如果嫌60秒太少了可以在重载方法的参数中设置
## 指定事务对象
除了上面提供的同线程的事务方法外FreeSql 还提供指定事务对象,方法外部扩展。
```csharp
orm.Update<xxx>().WithTransaction(指定事务)
.Set(a => a.Clicks + 1).ExecuteAffrows();
```
ISelect、IInsert、IUpdate、IDelete都支持 WithTransaction 方法。
## 事务为什么不适合异步方法
事务的操作会占用资源,导致其他地方的读写被阻塞,使用原则应该是尽快关闭释放资源。

@@ -136,6 +136,7 @@ var t10 = update.SetRaw("Title = {0}", "新标题").Where("Id = {0}", 1).ToSql()
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) |
| Where | \<this\> | T1 \| IEnumerable<T1> | 传入实体或集合,将其主键作为条件 |
| WhereExists | \<this\> | ISelect | 子查询是否存在 |
| WithTransaction | \<this\> | DbTransaction | 设置事务对象 |
| ToSql | string | | 返回即将执行的SQL语句 |
| ExecuteAffrows | long | | 执行SQL语句返回影响的行数 |
| ExecuteUpdated | List\<T1\> | | 执行SQL语句返回更新后的记录 |
| ExecuteUpdated | List\<T1\> | | 执行SQL语句返回更新后的记录 |

@@ -82,6 +82,8 @@ var t8 = fsql.Delete<Topic>().Where(items).ToSql();
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) |
| Where | \<this\> | T1 \| IEnumerable<T1> | 传入实体或集合,将其主键作为条件 |
| WhereExists | \<this\> | ISelect | 子查询是否存在 |
| WithTransaction | \<this\> | DbTransaction | 设置事务对象 |
| ToSql | string | | 返回即将执行的SQL语句 |
| ExecuteAffrows | long | | 执行SQL语句返回影响的行数 |
| ExecuteDeleted | List\<T1\> | | 执行SQL语句返回被删除的记录 |

@@ -1,7 +1,14 @@
完整版本:年数-月-日-当日版本号FreeSql 与 FreeSql.Repository 版本号相同。
## v0.3.11
- 增加 ISelect、IInsert、IUpdate、IDelete WithTransaction 方法,将事务对象暴露给外部;
- 增加 IAdo ExecuteXxx 系列方法重载,支持事务对象的传入;
## v0.1.14
- 增加 延时属性编译错误信息
- 增加 延时属性编译错误提示
- 优化 FreeSql.Repository Autofac 泛型注入;
## v0.1.13

@@ -63,3 +63,4 @@ FreeSql在查询数据下足了功能链式查询语法、多表查询、表
| As | \<this\> | string alias = "a" | 指定别名 |
| Master | \<this\> | | 指定从主库查询(默认查询从库) |
| Caching | \<this\> | int seconds, string key = null | 缓存查询结果 |
| WithTransaction | \<this\> | DbTransaction | 设置事务对象 |

@@ -86,6 +86,7 @@ var t6 = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime
| AppendData | \<this\> | T1 \| IEnumerable<T1> | 追加准备插入的实体 |
| InsertColumns | \<this\> | Lambda | 只插入的列 |
| IgnoreColumns | \<this\> | Lambda | 忽略的列 |
| WithTransaction | \<this\> | DbTransaction | 设置事务对象 |
| ToSql | string | | 返回即将执行的SQL语句 |
| ExecuteAffrows | long | | 执行SQL语句返回影响的行数 |
| ExecuteIdentity | long | | 执行SQL语句返回自增值 |