Example #1
0
        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;
        }
Example #2
0
        public void Dispose()
        {
            if (!this.isDisposed)
            {
                currScope = null;

                Thread.EndThreadAffinity();

                if (this.ToSaveAllChanges)
                {
                    this.northwindContext.SaveChanges();
                }
                this.northwindContext.Dispose();
                this.isDisposed = true;
            }
        }