Пример #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;
            }
        }