public void Dispose() { if (_disposed) { return; } if (_savedScope != null) { DbContextScope.SetAmbientScope(_savedScope); _savedScope = null; } _disposed = true; }
/// <summary> /// Makes the provided 'dbContextScope' available as the the ambient scope via the CallContext. /// </summary> internal static void SetAmbientScope(DbContextScope newAmbientScope) { if (newAmbientScope == null) { throw new ArgumentNullException("newAmbientScope"); } var current = CallContext.LogicalGetData(AmbientDbContextScopeKey) as InstanceIdentifier; if (current == newAmbientScope._instanceIdentifier) { return; } // Store the new scope's instance identifier in the CallContext, making it the ambient scope CallContext.LogicalSetData(AmbientDbContextScopeKey, newAmbientScope._instanceIdentifier); // Keep track of this instance (or do nothing if we're already tracking it) DbContextScopeInstances.GetValue(newAmbientScope._instanceIdentifier, key => newAmbientScope); }
public DbContextReadOnlyScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null) { _internalScope = new DbContextScope(joiningOption : joiningOption, readOnly : true, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory); }