Commit 9a068e79 authored by Marc Gravell's avatar Marc Gravell

Actually, it can work for sprocs without needing SqlClient, as the...

Actually, it can work for sprocs without needing SqlClient, as the "structured" bit is inferred and no type-name is required
parent c9569d3e
...@@ -3813,9 +3813,18 @@ public TableValuedParameter(DataTable table, string typeName) ...@@ -3813,9 +3813,18 @@ public TableValuedParameter(DataTable table, string typeName)
} }
void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name) void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name)
{ {
var param = new System.Data.SqlClient.SqlParameter(name, SqlDbType.Structured); var param = command.CreateParameter();
param.ParameterName = name;
param.Value = (object)table ?? DBNull.Value; param.Value = (object)table ?? DBNull.Value;
if (!string.IsNullOrEmpty(typeName)) param.TypeName = typeName; if (!string.IsNullOrEmpty(typeName))
{
var sqlParam = param as System.Data.SqlClient.SqlParameter;
if (sqlParam != null)
{
sqlParam.TypeName = typeName;
sqlParam.SqlDbType = SqlDbType.Structured;
}
}
command.Parameters.Add(param); command.Parameters.Add(param);
} }
} }
......
...@@ -2835,6 +2835,15 @@ public void DataTableParameters() ...@@ -2835,6 +2835,15 @@ public void DataTableParameters()
count = connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter("MyTVPType") }).First(); count = connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter("MyTVPType") }).First();
count.IsEqualTo(3); count.IsEqualTo(3);
try
{
connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter() }).First();
throw new InvalidOperationException();
} catch(Exception ex)
{
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
} }
#if POSTGRESQL #if POSTGRESQL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment