Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWorkScope"/> class.
 /// </summary>
 public UnitOfWorkScope() 
 {
     if ( currentScope == null )
     {
         DbContext = new RockContext();
         isDisposed = false;
         currentScope = this;
     }
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWorkScope"/> class using a custom dbContext
 /// </summary>
 public UnitOfWorkScope(DbContext context)
 {
     if ( currentScope == null )
     {
         DbContext = context;
         isDisposed = false;
         currentScope = this;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWorkScope"/> class using a custom dbContext
 /// </summary>
 public UnitOfWorkScope(DbContext context)
 {
     if (currentScope == null)
     {
         DbContext    = context;
         isDisposed   = false;
         currentScope = this;
     }
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWorkScope"/> class.
 /// </summary>
 public UnitOfWorkScope()
 {
     if (currentScope == null)
     {
         DbContext    = new RockContext();
         isDisposed   = false;
         currentScope = this;
     }
 }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitOfWorkScope"/> class.
        /// </summary>
        /// <param name="saveAllChangesAtScopeEnd">if set to <c>true</c> changes should be saved at scope end.</param>
        public UnitOfWorkScope( bool saveAllChangesAtScopeEnd )
        {
            if ( currentScope != null && !currentScope.isDisposed )
                throw new InvalidOperationException( "ObjectContextScope instances can not be nested" );

            SaveAllChangesAtScopeEnd = saveAllChangesAtScopeEnd;
            objectContext = new RockContext();
            isDisposed = false;
            //Thread.BeginThreadAffinity();  --Not supported with Medium Trust
            currentScope = this;
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitOfWorkScope"/> class.
        /// </summary>
        /// <param name="saveAllChangesAtScopeEnd">if set to <c>true</c> changes should be saved at scope end.</param>
        public UnitOfWorkScope(bool saveAllChangesAtScopeEnd)
        {
            if (currentScope != null && !currentScope.isDisposed)
            {
                throw new InvalidOperationException("ObjectContextScope instances can not be nested");
            }

            SaveAllChangesAtScopeEnd = saveAllChangesAtScopeEnd;
            objectContext            = new RockContext();
            isDisposed = false;
            //Thread.BeginThreadAffinity();  --Not supported with Medium Trust
            currentScope = this;
        }
Beispiel #7
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    if (DbContext != null)
                    {
                        DbContext.Dispose();
                        currentScope = null;
                    }
                }

                isDisposed = true;
            }
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!isDisposed)
            {
                currentScope = null;
                //Thread.EndThreadAffinity();  -- Not supported with Medium Trust

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

                objectContext.Dispose();
                isDisposed = true;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    currentScope = null;
                    //Thread.EndThreadAffinity();  -- Not supported with Medium Trust

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

                    objectContext.Dispose();
                }

                isDisposed = true;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose( bool disposing )
        {
            if ( !isDisposed )
            {
                if ( disposing )
                {
                    currentScope = null;
                    //Thread.EndThreadAffinity();  -- Not supported with Medium Trust

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

                    objectContext.Dispose();
                }

                isDisposed = true;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose( bool disposing )
        {
            if ( !isDisposed )
            {
                if ( disposing )
                {
                    if ( DbContext != null )
                    {
                        DbContext.Dispose();
                        currentScope = null;
                    }
                }

                isDisposed = true;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if ( !isDisposed )
            {
                currentScope = null;
                //Thread.EndThreadAffinity();  -- Not supported with Medium Trust

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

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