Dapper QueryMultiple Non-Mapped Stored Procedures

With dapper, I can do a batch run 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 way to get the data that I have seen so far is using

results.Read<Type>()

      

What if the results are not displayed on the object? For example, I write "generic" code to execute any SP with variable I / O parameters and result sets.

thank

+3


source to share


1 answer


Which API do you want? If you can process the meshes separately: do the following:

using(var multi = connection.QueryMultiple(...))
{
    while(!multi.IsConsumed) {
        // ...
    }
}

      

where ...

has access to:

  • Read()

    for strings dynamic

    - noting that each string also implementsIDictionary<string,object>

  • Read<T>

    () for typed strings via generics
  • Read(Type)

    for typed strings without generics
  • Read<DapperRow

    > () (actually this is simple T

    , which Read<T>()

    uses to implement Read()

    , but arguably more convenient), which provides slightly more metadata access


If you want to go to source IDataReader

, do the following:

using(var reader = connection.ExecuteReader(...)) {
    // whatever you want
}

      

As for the parameters: the class DynamicParameters

provides much richer access to parameter management, including parameter direction, etc.

+2


source







All Articles