Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper QueryMultiple Stored Procedures w/o mapping to Objects

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

like image 453
Bill Avatar asked Oct 20 '25 14:10

Bill


1 Answers

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() for dynamic rows - noting that each row also implements IDictionary<string,object>
  • Read<T>() for typed rows via generics
  • Read(Type) for typed rows without generics
  • Read<DapperRow>() (actually, this is just the T that Read<T>() uses to implement Read(), 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.

like image 184
Marc Gravell Avatar answered Oct 23 '25 08:10

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!