예제 #1
0
        public virtual DatabaseTransactionContextAcquisition AcquirePersistenceTransactionContext(SqlDatabaseContext sqlDatabaseContext)
        {
            SqlTransactionalCommandsContext retval;

            if (this.Transaction == null)
            {
                retval = sqlDatabaseContext.CreateSqlTransactionalCommandsContext(null);

                return(new DatabaseTransactionContextAcquisition(this, sqlDatabaseContext, retval));
            }
            else
            {
                TransactionEntry outValue;

                if (this.persistenceTransactionContextsBySqlDatabaseContexts.TryGetValue(sqlDatabaseContext, out outValue))
                {
                    retval = outValue.sqlDatabaseCommandsContext;
                }
                else
                {
                    retval = sqlDatabaseContext.CreateSqlTransactionalCommandsContext(this.Transaction);

                    this.persistenceTransactionContextsBySqlDatabaseContexts[sqlDatabaseContext] = new TransactionEntry(retval);
                }

                return(new DatabaseTransactionContextAcquisition(this, sqlDatabaseContext, retval));
            }
        }
예제 #2
0
        public virtual DatabaseTransactionContextAcquisition AcquirePersistenceTransactionContext(SqlDatabaseContext sqlDatabaseContext)
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException(nameof(TransactionContext));
            }

            SqlTransactionalCommandsContext commandsContext;

            if (!this.commandsContextsBySqlDatabaseContexts.TryGetValue(sqlDatabaseContext, out commandsContext))
            {
                commandsContext = sqlDatabaseContext.CreateSqlTransactionalCommandsContext(this.DataAccessTransaction);

                this.commandsContextsBySqlDatabaseContexts[sqlDatabaseContext] = commandsContext;
            }

            var startIndex = this.GetExecutionVersion();

            var retval = new DatabaseTransactionContextAcquisition(this, sqlDatabaseContext, commandsContext);

            if (this.DataAccessTransaction == null)
            {
                retval.Disposed += (s, e) =>
                {
                    if (this.GetExecutionVersion() <= startIndex)
                    {
                        this.dataAccessObjectDataContext = null;

                        foreach (var cc in this.commandsContextsBySqlDatabaseContexts.Values)
                        {
                            cc.Dispose();
                        }

                        this.commandsContextsBySqlDatabaseContexts.Clear();
                    }
                };
            }

            return(retval);
        }