Inheritance: IDisposable
Esempio n. 1
0
        public UnitOfWorkScope(bool saveAllChangesAtScopeEnd)
        {
            if (currentScope != null && !currentScope.isDisposed)
            {
                throw new InvalidOperationException("ObjectContextScope instances can not be nested.");
            }

            SaveAllChangesAtScopeEnd = saveAllChangesAtScopeEnd;
            objectContext = new GrassrootsContext();
            isDisposed = false;

            // TODO: Come up with cleaner solution to partial trust security policy issues around setting Thread Affinity
            try { Thread.BeginThreadAffinity(); }
            catch { }

            currentScope = this;
        }
Esempio n. 2
0
        public void Dispose()
        {
            if (!isDisposed)
            {
                currentScope = null;

                // TODO: Come up with cleaner solution to partial trust security policy issues around setting Thread Affinity
                try { Thread.EndThreadAffinity(); }
                catch { }

                if (SaveAllChangesAtScopeEnd)
                {
                    objectContext.SaveChanges();
                }

                objectContext.Dispose();
                isDisposed = true;
            }
        }