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; }
public void Dispose() { if ( !isDisposed ) { currentScope = null; Thread.EndThreadAffinity(); if ( SaveAllChangesAtScopeEnd ) { objectContext.SaveChanges(); } objectContext.Dispose(); isDisposed = true; } }