Dapper QueryMultiple存储过程,不映射到对象 [英] Dapper QueryMultiple Stored Procedures w/o mapping to Objects
问题描述
使用dapper,我可以对存储过程执行批处理,类似于:
With dapper, I can do batch execute for Stored Procedures, something similar to:
connection.Execute(@"
exec sp1 @i = @one, @y = @two
exec sp2 @i = @three",
new { one = 1, two = 2, three = 3 });
但是,检索到现在为止我看到的数据的唯一方法是使用
However, the only means of retrieving data that I have seen till now is by using
results.Read<Type>()
如果结果未映射到对象怎么办?例如,我正在编写通用代码以执行具有可变输入/输出参数&结果集。
What if the results don't map to an object? For instance, I am writing "generic" code to execute any SP with variable in/out parameters & result sets.
谢谢
推荐答案
您想要什么API?如果可以单独处理网格,请执行以下操作:
What API do you want? If you can process the grids separately: do that:
using(var multi = connection.QueryMultiple(...))
{
while(!multi.IsConsumed) {
// ...
}
}
其中 ...
可以访问:
-
Read()
用于动态
行-注意每一行也实现IDictionary< string,object>
-
Read< T>
()通过泛型输入类型的行 -
Read(Type)
用于没有泛型的类型化行 -
Read< DapperRow
>()(实际上,这只是Read< T>()$的
T
c $ c>用于实现Read()
,但也许更方便),它提供了对元数据的更多访问
Read()
fordynamic
rows - noting that each row also implementsIDictionary<string,object>
Read<T>
() for typed rows via genericsRead(Type)
for typed rows without genericsRead<DapperRow
>() (actually, this is just theT
thatRead<T>()
uses to implementRead()
, but perhaps more convenient), which provides slightly more access to metadata
如果您想放到原始的 IDataReader
,请执行以下操作:
If you want to drop to a raw IDataReader
, do that:
using(var reader = connection.ExecuteReader(...)) {
// whatever you want
}
关于参数: DynamicParameters
类提供了更丰富的参数控制访问权限,包括参数方向等。
With regards to parameters: the DynamicParameters
class provides much richer access to parameter control, including parameter-direction etc.
这篇关于Dapper QueryMultiple存储过程,不映射到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!