问题
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.
Thanks
回答1:
What API do you want? If you can process the grids separately: do that:
using(var multi = connection.QueryMultiple(...))
{
while(!multi.IsConsumed) {
// ...
}
}
where ...
has access to:
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
If you want to drop to a raw IDataReader
, do that:
using(var reader = connection.ExecuteReader(...)) {
// whatever you want
}
With regards to parameters: the DynamicParameters
class provides much richer access to parameter control, including parameter-direction etc.
来源:https://stackoverflow.com/questions/25620620/dapper-querymultiple-stored-procedures-w-o-mapping-to-objects