예제 #1
0
        public UnitOfWorkScope( bool saveAllChangesAtScopeEnd )
        {
            if ( currentScope != null && !currentScope.isDisposed )
                throw new InvalidOperationException( "ObjectContextScope instances can not be nested" );

            SaveAllChangesAtScopeEnd = saveAllChangesAtScopeEnd;
            objectContext = new Rock.EntityFramework.RockContext();
            isDisposed = false;
            Thread.BeginThreadAffinity();
            currentScope = this;
        }
예제 #2
0
        public void Dispose()
        {
            if ( !isDisposed )
            {
                currentScope = null;
                Thread.EndThreadAffinity();

                if ( SaveAllChangesAtScopeEnd )
                {
                    objectContext.SaveChanges();
                }

                objectContext.Dispose();
                isDisposed = true;
            }
        }