update

28810
2020-01-08 12:38:18 +08:00
parent 0789e5d9ef
commit 5817b0eeb3
2 changed files with 6 additions and 6 deletions

@@ -5,7 +5,7 @@ FreeSql实现了四种数据库事务的使用方法。事务用于处理数据
FreeSql 提供了指定事务对象的方法,将事务对象暴露给外部;
```csharp
orm.Update<xxx>().WithTransaction(指定事务)
fsql.Update<xxx>().WithTransaction(指定事务)
.Set(a => a.Clicks + 1).ExecuteAffrows();
```
@@ -22,27 +22,26 @@ ISelect、IInsert、IUpdate、IDelete都支持 WithTransaction 方法。
第一步成功了,到了第二步发现库存不足时,事务可以回滚,扣余额的数据将不生效。
```csharp
//假设已经有了其他wiki页的IFreeSql声明
fsql.Transaction(() => {
//fsql.Ado.TransactionCurrentThread 此属性可得到事务对象
var affrows = fsql.Update<User>().Set(a => a.Wealth - 100)
.Where(a => a.Wealth >= 100)
//判断别让用户余额扣成负数
.ExecuteAffrows();
if (affrows < 1) {
if (affrows < 1)
throw new Exception("用户余额不足");
//抛出异常,事务退出
}
affrows = fsql.Update<Goods>().Set(a => a.Stock - 1)
.Where(a => a.Stock > 0)
//判断别让用库存扣成负数
.ExecuteAffrows();
if (affrows < 1) {
if (affrows < 1)
throw new Exception("商品库存不足");
//抛出异常,回滚事务,事务退出
//用户余额的扣除将不生效
}
//程序执行在此处,说明都扣成功了,事务完成并提交
});

@@ -10,6 +10,7 @@
- 完善 [Column(ServerTime = Utc)] 特性,对 Update 时也能生效;
- 完善 [Column(MapType = typeof(byte[]))] 对 Guid/string 的映射支持;#178
- 完善 MapType byte[] 对 Contains/Parse 表达式解析的处理;
- 修复 DbConnectionPool.Return 在 Sqlite 下的 bug#179
## v1.0.1