Esempio n. 1
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);
        }
Esempio n. 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;
		}