关于SqlSugar 事务的建议 返回
SqlSugar
待处理
3
324
悬赏:5 飞吻
建议去掉事务支持,是否需要放到事务中执行交给用户,否则写的多个逻辑方法不能复用,或者不能在一个事务中回滚; 推荐 使用 TransactionScope
热忱回答(3)
-
Somebody VIP0
2周前例如:
SaveAccount(Account acc )
{
db.Updateable(acc ).ExecuteCommand();
}
Pay(Account from, Account to,double amount)
{
using(TransactionScope scope=new TransactionScope()){
from.Money-=amount;
to.Money+=amount;
SaveAccount(from);
SaveAccount(to);
scope.Complete();
}
}
0 回复 -
Somebody VIP0
2周前还有,数据库连接在不同的线程会用同一个,有可能导致A线程用完连接,并关闭连接,但是B线程已经执行了部分sql,而不知道连接被关闭的情况。
0 回复 -
fate sta VIP0
2周前事务就是一个整体,事务可以跨方法,不能跨线程。这个是ADO.NET约定的。
0 回复