提交 9a068e79 编写于 作者: M 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
上级 c9569d3e
......@@ -3813,9 +3813,18 @@ public TableValuedParameter(DataTable table, string typeName)
}
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;
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);
}
}
......
......@@ -2835,6 +2835,15 @@ public void DataTableParameters()
count = connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter("MyTVPType") }).First();
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册