Example #1
0
        public DbContextScope(DbContextScopeOption joiningOption, bool readOnly, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null)
        {
            if (isolationLevel.HasValue && joiningOption == DbContextScopeOption.JoinExisting)
            {
                throw new ArgumentException("Cannot join an ambient DbContextScope when an explicit database transaction is required. When requiring explicit database transactions to be used (i.e. when the 'isolationLevel' parameter is set), you must not also ask to join the ambient context (i.e. the 'joinAmbient' parameter must be set to false).");
            }

            this.disposed  = false;
            this.completed = false;
            this.readOnly  = readOnly;

            this.parentScope = GetAmbientScope();
            if (this.parentScope != null && joiningOption == DbContextScopeOption.JoinExisting)
            {
                if (this.parentScope.readOnly && !this.readOnly)
                {
                    throw new InvalidOperationException("Cannot nest a read/write DbContextScope within a read-only DbContextScope.");
                }

                this.nested     = true;
                this.dbContexts = this.parentScope.dbContexts;
            }
            else
            {
                this.nested     = false;
                this.dbContexts = new DbContextCollection(readOnly, isolationLevel, dbContextFactory);
            }

            SetAmbientScope(this);
        }
Example #2
0
 protected virtual void RunBeforeSave(DbContextCollection dbContextCollection)
 {
 }