1#if !NETFX_CORE && !(ANDROID || IOS)
38 where C : IDbConnection, new()
39 where T : IDbTransaction
41 private static object _lock =
new object();
42 private C _connection;
43 private T _transaction;
44 private string _connectionString;
45 private string _label;
88 return GetManager(database, isDatabaseName,
"default");
110#if NETSTANDARD2_0 || NET5_0
111 throw new NotSupportedException(
"isDatabaseName==true");
113 var connection = ConfigurationManager.ConnectionStrings[database];
114 if (connection ==
null)
117 var conn = ConfigurationManager.ConnectionStrings[database].ConnectionString;
118 if (
string.IsNullOrEmpty(conn))
126 var contextLabel = GetContextName(database, label);
128 if (ApplicationContext.LocalContext.Contains(contextLabel))
136 ApplicationContext.LocalContext[contextLabel] = mgr;
146 _connectionString = connectionString;
149 _connection =
new C();
150 _connection.ConnectionString = connectionString;
153 _transaction = (T)_connection.BeginTransaction();
157 private static string GetContextName(
string connectionString,
string label)
159 return "__transaction:" + label +
"-" + connectionString;
187 private bool _commit =
false;
202#region Reference counting
204 private int _refCount;
212 get {
return _refCount; }
215 private void AddRef()
230 _transaction.Commit();
232 _transaction.Rollback();
236 _transaction.Dispose();
237 _connection.Dispose();
238 ApplicationContext.LocalContext.Remove(GetContextName(_connectionString, _label));
Provides an automated way to reuse open database connections and associated ADO.NET transactions with...
void Commit()
Indicates that the current transactional scope has completed successfully.
int RefCount
Gets the current reference count for this object.
static TransactionManager< C, T > GetManager(string database)
Gets the TransactionManager object for the specified database.
T Transaction
Gets a reference to the current ADO.NET transaction object.
static TransactionManager< C, T > GetManager(string database, string label)
Gets the TransactionManager object for the specified database.
C Connection
Gets a reference to the current ADO.NET connection object that is associated with current trasnaction...
void Dispose()
Dispose object, dereferencing or disposing the connection it is managing.
static TransactionManager< C, T > GetManager(string database, bool isDatabaseName, string label)
Gets the TransactionManager object for the specified database.
static TransactionManager< C, T > GetManager(string database, bool isDatabaseName)
Gets the TransactionManager object for the specified database.
A strongly-typed resource class, for looking up localized strings, etc.
static string DatabaseNameNotFound
Looks up a localized string similar to Database name not found in config file ({0}).