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.