Frapid.Mapper.Database.MapperDb.OpenSharedConnectionAsync C# (CSharp) Method

OpenSharedConnectionAsync() public method

public OpenSharedConnectionAsync ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public async Task OpenSharedConnectionAsync()
        {
            if (this.Connection.State == ConnectionState.Broken)
            {
                this.Connection.Close();
            }

            if (this.Connection.State == ConnectionState.Closed)
            {
                await this.Connection.OpenAsync().ConfigureAwait(false);
            }
        }

Usage Example

Example #1
0
        public virtual async Task NonQueryAsync(MapperDb db, DbCommand command)
        {
            var connection = db.GetConnection();
            if (connection == null)
            {
                throw new MapperException("Could not create database connection.");
            }

            await db.OpenSharedConnectionAsync().ConfigureAwait(false);
            command.Connection = connection;
            command.Transaction = db.GetTransaction();

            await command.ExecuteNonQueryAsync().ConfigureAwait(false);
        }