Dapper是否支持SQL 2008表值参数?

有谁知道是否可以使用Dapper 将表值参数数据传递到存储过程?



慕码人8056858
浏览 585回答 3
3回答

慕神8447489

现在(对Dapper 1.26或更高版本)直接支持烘焙到dapper中的表值参数。对于存储过程,由于数据类型已内置在sproc API中,因此您所需要做的就是提供DataTable:var data = connection.Query<SomeType>(..., new {&nbsp; &nbsp; id=123, name="abc", values = someTable}, ...);对于直接命令文本,您还有两个选择:使用辅助方法告诉它自定义数据类型:var data = connection.Query<SomeType>(..., new {&nbsp; &nbsp; id=123, name="abc", values = someTable.AsTableValuedParameter("mytype")}, ...);告诉数据表本身要使用哪种自定义数据类型:someTable.SetTypeName("mytype");var data = connection.Query<SomeType>(..., new {&nbsp; &nbsp; id=123, name="abc", values = someTable}, ...);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;这些中的任何一个都可以正常工作。
打开App,查看更多内容
随时随地看视频慕课网APP