mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	debug UnitOfWork Destructor #131
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
using SafeObjectPool;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Data.Common;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
@@ -27,7 +28,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Dictionary<int, Transaction2> _trans = new Dictionary<int, Transaction2>();
 | 
			
		||||
        private ConcurrentDictionary<int, Transaction2> _trans = new ConcurrentDictionary<int, Transaction2>();
 | 
			
		||||
        private object _trans_lock = new object();
 | 
			
		||||
 | 
			
		||||
        public DbTransaction TransactionCurrentThread => _trans.TryGetValue(Thread.CurrentThread.ManagedThreadId, out var conn) && conn.Transaction?.Connection != null ? conn.Transaction : null;
 | 
			
		||||
@@ -54,7 +55,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
            if (_trans.ContainsKey(tid)) CommitTransaction();
 | 
			
		||||
 | 
			
		||||
            lock (_trans_lock)
 | 
			
		||||
                _trans.Add(tid, tran);
 | 
			
		||||
                _trans.TryAdd(tid, tran);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AutoCommitTransaction()
 | 
			
		||||
@@ -74,7 +75,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
            if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
 | 
			
		||||
                lock (_trans_lock)
 | 
			
		||||
                    if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
 | 
			
		||||
                        _trans.Remove(tran.Conn.LastGetThreadId);
 | 
			
		||||
                        _trans.TryRemove(tran.Conn.LastGetThreadId, out var oldtran);
 | 
			
		||||
 | 
			
		||||
            Exception ex = null;
 | 
			
		||||
            var f001 = isCommit ? "提交" : "回滚";
 | 
			
		||||
 
 | 
			
		||||
@@ -58,13 +58,13 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
 | 
			
		||||
        static object syncStructureLock = new object();
 | 
			
		||||
        object _dicSycedLock = new object();
 | 
			
		||||
        Dictionary<Type, ConcurrentDictionary<string, bool>> _dicSynced = new Dictionary<Type, ConcurrentDictionary<string, bool>>();
 | 
			
		||||
        ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicSynced = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
 | 
			
		||||
        internal ConcurrentDictionary<string, bool> _dicSycedGetOrAdd(Type entityType)
 | 
			
		||||
        {
 | 
			
		||||
            if (_dicSynced.TryGetValue(entityType, out var trydic) == false)
 | 
			
		||||
                lock (_dicSycedLock)
 | 
			
		||||
                    if (_dicSynced.TryGetValue(entityType, out trydic) == false)
 | 
			
		||||
                        _dicSynced.Add(entityType, trydic = new ConcurrentDictionary<string, bool>());
 | 
			
		||||
                        _dicSynced.TryAdd(entityType, trydic = new ConcurrentDictionary<string, bool>());
 | 
			
		||||
            return trydic;
 | 
			
		||||
        }
 | 
			
		||||
        internal void _dicSycedTryAdd(Type entityType, string tableName = null) =>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user