/// <summary> /// Creates the command. /// </summary> /// <param name="sqlTransConnection">The SQL trans connection.</param> /// <param name="parameter">The parameter.</param> /// <returns>a new SqlCommand</returns> /// <exception cref="NotSupportedException"></exception> public virtual SqlCommand CreateCommand(SqlTransConnection sqlTransConnection, TIn parameter) { var command = this.CreateCommand(sqlTransConnection); if (parameter is IEntity entity) { foreach (var sqlParameterDefinition in this.ParameterDefinitions.Values) { var boundParameter = sqlParameterDefinition.AddParameter(command); var parameterValue = entity.GetProperty(sqlParameterDefinition.Name, false, null); boundParameter.SetValue(parameterValue); } } else { throw new NotSupportedException($"{parameter.GetType().FullName} is not a IEntity - implementation missing"); } return(command); }
/// <summary> /// Creates the command. /// </summary> /// <param name="sqlTransConnection">The SQL trans connection.</param> /// <returns></returns> protected virtual SqlCommand CreateCommand(SqlTransConnection sqlTransConnection) => sqlTransConnection.SqlCommand(System.Data.CommandType.StoredProcedure, this._SqlName);
/// <summary> /// Executes the non query asynchronous. /// </summary> /// <param name="sqlTransConnection">The SQL trans connection.</param> /// <param name="parameter">The parameter.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <int> ExecuteNonQueryAsync(SqlTransConnection sqlTransConnection, TIn parameter, CancellationToken cancellationToken = default(CancellationToken)) { using (var command = this.CreateCommand(sqlTransConnection, parameter)) { return(await command.ExecuteNonQueryAsync(cancellationToken)); } }