示例#1
0
        // Only methods with a non-trivial implementation are here, the rest are in the DataAccessWrapper abstract class.
        #region DataAccessWrapper interface
        /// <summary>
        /// Creates a new DbConnection. You do not normally need to call this! (MightyOrm normally manages its own
        /// connections. Create a connection here and pass it on to other MightyOrm commands only in non-standard use
        /// cases where you need to explicitly manage transactions or share connections, e.g. when using explicit cursors.)
        /// </summary>
        /// <returns></returns>
        override public DbConnection OpenConnection()
        {
            var connection = Factory.CreateConnection();

            connection = DataProfiler.ConnectionWrapping(connection);
            connection.ConnectionString = ConnectionString;
            connection.Open();
            return(connection);
        }
示例#2
0
        /// <summary>
        /// Creates a new DbConnection. You do not normally need to call this! (MightyOrm normally manages its own
        /// connections. Create a connection here and pass it on to other MightyOrm commands only in non-standard use
        /// cases where you need to explicitly manage transactions or share connections, e.g. when using explicit cursors.)
        /// </summary>
        /// <param name="cancellationToken">Async <see cref="CancellationToken"/></param>
        /// <returns></returns>
        override public async Task <DbConnection> OpenConnectionAsync(CancellationToken cancellationToken)
        {
            var connection = Factory.CreateConnection();

            connection = DataProfiler.ConnectionWrapping(connection);
            connection.ConnectionString = ConnectionString;
            await connection.OpenAsync(cancellationToken).ConfigureAwait(false);

            return(connection);
        }
示例#3
0
        /// <summary>
        /// Internal usage only, creates a new DbConnection.
        /// </summary>
        /// <param name="isInternal"><cref>true</cref> if called internally</param>
        /// <param name="connectionString">Connection string to use</param>
        /// <returns></returns>
        internal DbConnection OpenConnection(bool isInternal, string connectionString = null)
        {
            if (string.IsNullOrEmpty(ConnectionString) && string.IsNullOrEmpty(connectionString))
            {
                if (isInternal)
                {
                    throw new InvalidOperationException("Connection needed to proceed, but no DbConnection object and no per-instance or global connection string available");
                }
                else
                {
                    throw new InvalidOperationException("No connection string provided, and no per-instance or global connection string available");
                }
            }
            var connection = Factory.CreateConnection();

            connection = DataProfiler.ConnectionWrapping(connection);
            connection.ConnectionString = string.IsNullOrEmpty(connectionString) ? ConnectionString : connectionString;
            connection.Open();
            return(connection);
        }