示例#1
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_savedScope != null)
            {
                AmbientScope.SetAmbientScope(_savedScope);
                _savedScope = null;
            }

            _disposed = true;
        }
示例#2
0
        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);
        }
示例#3
0
 public DbContextReadOnlyScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null)
 {
     _internalScope = new DbContextScope(joiningOption : joiningOption, readOnly : true, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory);
 }