12using System.Data.Entity.Core.Objects;
38 private static object _lock =
new object();
40 private string _connectionString;
41 private string _label;
84 return GetManager(database, isDatabaseName,
"default");
106 var connection = ConfigurationManager.ConnectionStrings[database];
107 if (connection ==
null)
109 var conn = ConfigurationManager.ConnectionStrings[database].ConnectionString;
110 if (
string.IsNullOrEmpty(conn))
117 var contextLabel = GetContextName(database, label);
119 if (ApplicationContext.LocalContext.Contains(contextLabel))
127 ApplicationContext.LocalContext[contextLabel] = mgr;
137 _connectionString = connectionString;
139 _context = (C)(Activator.CreateInstance(typeof(C), connectionString));
140 _context.Connection.Open();
143 private static string GetContextName(
string connectionString,
string label)
145 return "__octx:" + label +
"-" + connectionString;
160#region Reference counting
162 private int _refCount;
170 get {
return _refCount; }
173 private void AddRef()
186 _context.Connection.Close();
188 ApplicationContext.LocalContext.Remove(GetContextName(_connectionString, _label));
Provides an automated way to reuse Entity Framework object context objects within the context of a si...
static ObjectContextManager< C > GetManager(string database)
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, bool isDatabaseName, string label)
Gets the ObjectContextManager object for the specified database.
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.
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}).