1#if !NETSTANDARD2_0 && !NET5_0
11using System.Data.Objects;
37 private static object _lock =
new object();
39 private string _connectionString;
40 private string _label;
83 return GetManager(database, isDatabaseName,
"default");
105 var connection = ConfigurationManager.ConnectionStrings[database];
106 if (connection ==
null)
108 var conn = ConfigurationManager.ConnectionStrings[database].ConnectionString;
109 if (
string.IsNullOrEmpty(conn))
116 var contextLabel = GetContextName(database, label);
118 if (ApplicationContext.LocalContext.Contains(contextLabel))
126 ApplicationContext.LocalContext[contextLabel] = mgr;
136 _connectionString = connectionString;
138 _context = (C)(Reflection.MethodCaller.CreateInstance(typeof(C), connectionString));
139 _context.Connection.Open();
142 private static string GetContextName(
string connectionString,
string label)
144 return "__octx:" + label +
"-" + connectionString;
159#region Reference counting
161 private int _refCount;
169 get {
return _refCount; }
172 private void AddRef()
185 _context.Connection.Close();
187 ApplicationContext.LocalContext.Remove(GetContextName(_connectionString, _label));
Provides an automated way to reuse Entity Framework object context objects within the context of a si...
void Dispose()
Dispose object, dereferencing or disposing the context it is managing.
C ObjectContext
Gets the EF object context object.
static ObjectContextManager< C > GetManager(string database, bool isDatabaseName)
Gets the ObjectContextManager object for the specified database.
int RefCount
Gets the current reference count for this object.
static ObjectContextManager< C > GetManager(string database, string label)
Gets the ObjectContextManager object for the specified database.
static ObjectContextManager< C > GetManager(string database)
Gets the ObjectContextManager object for the specified database.
static ObjectContextManager< C > GetManager(string database, bool isDatabaseName, string label)
Gets the ObjectContextManager 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}).