Exemple #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;
     }
 }
Exemple #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;
     }
 }
Exemple #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;
     }
 }
Exemple #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;
     }
 }
Exemple #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;
        }
Exemple #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;
        }
Exemple #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;
            }
        }
Exemple #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;
            }
        }
Exemple #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;
            }
        }
Exemple #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;
            }
        }
Exemple #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;
            }
        }