Does anyone know if is possible to pass table-valued parameter data to a stored procedure with Dapper?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
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
:For direct command-text you have two other options:
use a helper method to tell it the custom data type:
tell the data-table itself what custom data type to use:
Any of these should work fine.
Yes, we support them but you will need to code your own helpers.
For example:
Make sure you properly test performance for table valued params. When I tested this for passing int lists it was significantly slower than passing in multiple params.
I am totally not against having some SQL Server specific helpers for dapper in the contrib project, however the core dapper avoids adding vendor specific tricks where possible.
I know this ticket is OLD, very old, but wanted to let you know that I have published Dapper.Microsoft.Sql package, which supports generic TVPs.
https://www.nuget.org/packages/Dapper.Microsoft.Sql/
Sample use:
It is based on the original classes from Dapper test project.
Enjoy!
today it isn't. We actually investigated table-valed-parameters for our cheeky "in" implementation (
where col in @values
), but were very unimpressed by performance. However in the context of a SPROC it makes sense.Your best bet is to log this as an issue on the project site so we can track/prioritise it. It sounds like something will be doable, though, probably similar to the DbString or DynamicParameters options.
But today? No.