小巧玲珑是否支持SQL Server 2008表值参数? [英] Does Dapper support SQL 2008 Table-Valued Parameters?
问题描述
有谁知道是否可以表值参数的数据传递给存储过程用小巧精致的?
Does anyone know if is possible to pass table-valued parameter data to a stored procedure with Dapper?
推荐答案
现在有(N小巧玲珑1.26及更高版本),烤成短小精悍的表值参数的直接支持。在存储过程的情况下,由于数据类型是内置的存储过程的API,所有你需要做的是提供一个数据表
:
There is now (n Dapper 1.26 and higher) direct support for table-valued parameters baked into dapper. In the case of stored procedures, since the data type is built into the sproc API, all you need to do is supply a DataTable
:
var data = connection.Query<SomeType>(..., new {
id=123, name="abc", values = someTable
}, ...);
有关的直接命令文本,你有两个选项:
For direct command-text you have two other options:
-
使用一个辅助方法来告诉它的自定义数据类型:
use a helper method to tell it the custom data type:
var data = connection.Query<SomeType>(..., new {
id=123, name="abc", values = someTable.AsTableValuedParameter("mytype")
}, ...);
告诉数据表本身要使用的自定义数据类型:
tell the data-table itself what custom data type to use:
someTable.SetTypeName("mytype");
var data = connection.Query<SomeType>(..., new {
id=123, name="abc", values = someTable
}, ...);
所有的这些都应该很好地工作。
Any of these should work fine.
这篇关于小巧玲珑是否支持SQL Server 2008表值参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!