SenseNet.ContentRepository.Storage.TransactionScope.Commit C# (CSharp) Method

Commit() public static method

Commits the transaction.
public static Commit ( ) : void
return void
        public static void Commit()
        {
            if(_notSupported)
                return;

            ITransactionProvider tran = ContextHandler.GetTransaction();
            if(tran == null) // !IsActive
                throw new InvalidOperationException(); // Transaction is not Active.

            try
            {
                tran.Commit();
                
                var queue = ContextHandler.GetTransactionQueue();
                if (queue != null)
                    queue.Commit();

                OnCommitTransaction(tran, EventArgs.Empty);
            }
            finally
            {
                ContextHandler.SetTransaction(null);
                ContextHandler.SetTransactionQueue(null);
                tran.Dispose();
            }
        }

Usage Example

        /// <summary>
        /// Marks orphaned file records (the ones that do not have a referencing binary record anymore) as Deleted.
        /// </summary>
        public void CleanupFilesSetDeleteFlag()
        {
            var isLocalTransaction = false;

            if (!TransactionScope.IsActive)
            {
                TransactionScope.Begin();
                isLocalTransaction = true;
            }

            try
            {
                using (var proc = new SqlProcedure {
                    CommandText = CleanupFileSetIsdeletedScript, CommandType = CommandType.Text
                })
                {
                    proc.CommandType = CommandType.Text;
                    proc.ExecuteNonQuery();
                }

                if (isLocalTransaction && TransactionScope.IsActive)
                {
                    TransactionScope.Commit();
                }
            }
            catch (Exception ex)
            {
                if (isLocalTransaction && TransactionScope.IsActive)
                {
                    TransactionScope.Rollback();
                }

                throw new DataException("Error during setting deleted flag on files.", ex);
            }
        }
All Usage Examples Of SenseNet.ContentRepository.Storage.TransactionScope::Commit