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:
		@@ -221,7 +221,7 @@ namespace FreeSql
 | 
				
			|||||||
                AllSets.Clear();
 | 
					                AllSets.Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (_isUseUnitOfWork)
 | 
					                if (_isUseUnitOfWork)
 | 
				
			||||||
                    UnitOfWork?.Rollback();
 | 
					                    UnitOfWork?.Dispose();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            finally
 | 
					            finally
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
using SafeObjectPool;
 | 
					using SafeObjectPool;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Collections.Concurrent;
 | 
				
			||||||
using System.Data.Common;
 | 
					using System.Data.Common;
 | 
				
			||||||
using System.Diagnostics;
 | 
					using System.Diagnostics;
 | 
				
			||||||
using System.Linq;
 | 
					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();
 | 
					        private object _trans_lock = new object();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public DbTransaction TransactionCurrentThread => _trans.TryGetValue(Thread.CurrentThread.ManagedThreadId, out var conn) && conn.Transaction?.Connection != null ? conn.Transaction : null;
 | 
					        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();
 | 
					            if (_trans.ContainsKey(tid)) CommitTransaction();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            lock (_trans_lock)
 | 
					            lock (_trans_lock)
 | 
				
			||||||
                _trans.Add(tid, tran);
 | 
					                _trans.TryAdd(tid, tran);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void AutoCommitTransaction()
 | 
					        private void AutoCommitTransaction()
 | 
				
			||||||
@@ -74,7 +75,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
            if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
 | 
					            if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
 | 
				
			||||||
                lock (_trans_lock)
 | 
					                lock (_trans_lock)
 | 
				
			||||||
                    if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
 | 
					                    if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
 | 
				
			||||||
                        _trans.Remove(tran.Conn.LastGetThreadId);
 | 
					                        _trans.TryRemove(tran.Conn.LastGetThreadId, out var oldtran);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Exception ex = null;
 | 
					            Exception ex = null;
 | 
				
			||||||
            var f001 = isCommit ? "提交" : "回滚";
 | 
					            var f001 = isCommit ? "提交" : "回滚";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,13 +58,13 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        static object syncStructureLock = new object();
 | 
					        static object syncStructureLock = new object();
 | 
				
			||||||
        object _dicSycedLock = 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)
 | 
					        internal ConcurrentDictionary<string, bool> _dicSycedGetOrAdd(Type entityType)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (_dicSynced.TryGetValue(entityType, out var trydic) == false)
 | 
					            if (_dicSynced.TryGetValue(entityType, out var trydic) == false)
 | 
				
			||||||
                lock (_dicSycedLock)
 | 
					                lock (_dicSycedLock)
 | 
				
			||||||
                    if (_dicSynced.TryGetValue(entityType, out trydic) == false)
 | 
					                    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;
 | 
					            return trydic;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        internal void _dicSycedTryAdd(Type entityType, string tableName = null) =>
 | 
					        internal void _dicSycedTryAdd(Type entityType, string tableName = null) =>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user