Example #1
0
        /// <summary>
        /// Creates a disposable container with a database connection, creating a new connection if necessary
        /// </summary>
        /// <param name="connection">Database connection (null for a new connection)</param>
        /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param>
        public static async Task <DBSqlServerConnection> CreateAsync(DBSqlServerConnection connection, string connectionStringName)
        {
            var newConnection = new DBSqlServerConnection();

            if (connection is null)
            {
                newConnection.DisposeConnection = true;
                newConnection.Connection        = await DBSqlServerConnectionInstance.OpenAsync(connectionStringName).ConfigureAwait(false);
            }
            else
            {
                newConnection.DisposeConnection = false;
                newConnection.Connection        = connection.Connection;
            }

            return(newConnection);
        }
Example #2
0
        /// <summary>
        /// Creates a disposable container with a database connection, creating a new connection if necessary
        /// </summary>
        /// <param name="connection">Database connection (null for a new connection)</param>
        /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param>
        protected static async Task <T> CreateAsync <T>(DBSqlServerConnection connection, string connectionStringName) where T : DBSqlServerConnection
        {
            var newConnection = (T)Activator.CreateInstance(type: typeof(T), nonPublic: true);

            if (connection is null)
            {
                newConnection.DisposeConnection = true;
                newConnection.Connection        = await DBSqlServerConnectionInstance.OpenAsync(connectionStringName).ConfigureAwait(false);
            }
            else
            {
                newConnection.DisposeConnection = false;
                newConnection.Connection        = connection.Connection;
            }

            return(newConnection);
        }