Example #1
0
        public async Task <IDataConnectionTransaction> BeginTransaction()
        {
            if (CurrentTransaction != null)
            {
                throw new InvalidOperationException("Transaction is already started");
            }

            var connection = await GetOpenConnectionAsync();

            var transaction = connection.BeginTransaction();

            var result = new DataConnectionTransaction <T>(this, transaction);

            return(result);
        }
Example #2
0
        /// <summary>
        ///     Specifies an existing <see cref="DbTransaction" /> to be used for database operations.
        /// </summary>
        /// <param name="transaction"> The transaction to be used. </param>
        internal virtual IDataConnectionTransaction UseTransaction(DataConnectionTransaction <T> transaction)
        {
            if (transaction == null)
            {
                if (DataConnectionTransaction != null)
                {
                    DataConnectionTransaction = null;
                }
            }
            else
            {
                if (CurrentTransaction != null)
                {
                    throw new InvalidOperationException("Transaction is already started");
                }

                DataConnectionTransaction = transaction;
            }

            return(DataConnectionTransaction);
        }