Assuming the OP used the same generic TableValuedParameter class I did, the solution lies in its implementation of the SqlMapper.IDynamicParameters AddParameters
method, and the fact that it explicitly sets the CommandType of the IDbCommand to CommandType.StoredProcedure as shown below:
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
var list = _values.Select(s =>
{
var sqlDataRecord = new SqlDataRecord(_tvpDefinition);
_actionMapping(sqlDataRecord, s);
return sqlDataRecord;
}).ToList();
if (list.Count == 0)
{
return;
}
var sqlParameter = sqlCommand.Parameters.Add(_name, SqlDbType.Structured);
sqlParameter.Direction = ParameterDirection.Input;
sqlParameter.TypeName = _typeName;
sqlParameter.Value = list;
}
By removing the line that explicitly sets the CommandType, the TableValuedParameter class now works for normal queries, too.
internal
class so you can't create a new instance of it directly.