mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 fsql.Transaction 线程事务;
This commit is contained in:
parent
913b0ac5ce
commit
79c17d7f60
@ -138,6 +138,15 @@ namespace base_entity
|
||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||
#endregion
|
||||
|
||||
for (var a = 0; a < 1000; a++)
|
||||
{
|
||||
fsql.Transaction(() =>
|
||||
{
|
||||
var tran = fsql.Ado.TransactionCurrentThread;
|
||||
tran.Rollback();
|
||||
});
|
||||
}
|
||||
|
||||
fsql.UseJsonMap();
|
||||
var bid1 = 10;
|
||||
var list1 = fsql.Select<A>()
|
||||
|
@ -74,17 +74,20 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
private void CommitTransaction(bool isCommit, Transaction2 tran, Exception rollbackException, string remark = null)
|
||||
{
|
||||
if (tran == null || tran.Transaction == null || tran.Transaction.Connection == null) return;
|
||||
if (tran == null || tran.Transaction == null || tran.Connection == null) return;
|
||||
_trans.TryRemove(tran.Connection.LastGetThreadId, out var oldtran);
|
||||
|
||||
Exception ex = null;
|
||||
if (string.IsNullOrEmpty(remark)) remark = isCommit ? "提交" : "回滚";
|
||||
try
|
||||
{
|
||||
if (tran.Transaction.Connection != null) //用户自行 Commit、Rollback
|
||||
{
|
||||
Trace.WriteLine($"线程{tran.Connection.LastGetThreadId}事务{remark}");
|
||||
if (isCommit) tran.Transaction.Commit();
|
||||
else tran.Transaction.Rollback();
|
||||
}
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
ex = ex2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user