public UnitOfWorkScope(bool toSaveAllChanges) { if ((currScope != null) && (!currScope.isDisposed)) { throw new InvalidOperationException(String.Format("Nestig of nothwindContexts is not allowed!")); } this.toSaveAllChanges = toSaveAllChanges; northwindContext = new northwindEntities(); this.isDisposed = false; Thread.BeginThreadAffinity(); currScope = this; }
public void Dispose() { if (!this.isDisposed) { currScope = null; Thread.EndThreadAffinity(); if (this.ToSaveAllChanges) { this.northwindContext.SaveChanges(); } this.northwindContext.Dispose(); this.isDisposed = true; } }