1#if !NETSTANDARD2_0 && !NET5_0
11using System.Data.Linq;
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));
142 private static string GetContextName(
string connectionString,
string label)
144 return "__ctx:" + label +
"-" + connectionString;
158#region Reference counting
160 private int _refCount;
168 get {
return _refCount; }
171 private void AddRef()
185 ApplicationContext.LocalContext.Remove(GetContextName(_connectionString, _label));
Provides an automated way to reuse LINQ data context objects within the context of a single data port...
int RefCount
Gets the current reference count for this object.
static ContextManager< C > GetManager(string database, bool isDatabaseName)
Gets the ContextManager object for the specified database.
static ContextManager< C > GetManager(string database, string label)
Gets the ContextManager object for the specified database.
void Dispose()
Dispose object, dereferencing or disposing the context it is managing.
C DataContext
Gets the LINQ data context object.
static ContextManager< C > GetManager(string database)
Gets the ContextManager object for the specified database.
static ContextManager< C > GetManager(string database, bool isDatabaseName, string label)
Gets the ContextManager 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}).