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

                Thread.EndThreadAffinity();

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