From 429ebee408c0500c75527f600ebb69bddbabb0c4 Mon Sep 17 00:00:00 2001 From: Fat Person <58603432@qq.com> Date: Mon, 12 May 2025 18:48:19 +0800 Subject: [PATCH] Update UnitOfWork.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ..临时修改..期望赶紧fix一下..复现方式也挺简单的, using var dbTran = xx.CreateUnitOfWork(); using var tranInstance = dbTran.GetOrBeginTransaction(); do.... tranInstance.commit() return ...这里销毁就会默认调用rollback,比较离谱 --- FreeSql.DbContext/UnitOfWork/UnitOfWork.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs b/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs index 86644bf2b..c7014f0d6 100644 --- a/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs +++ b/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs @@ -165,10 +165,11 @@ public void Rollback() int _disposeCounter; public void Dispose() { + if (Interlocked.Increment(ref _disposeCounter) != 1) return; try { - this.Rollback(); + if(_tranBefore is not null) this.Rollback(); } finally {