4

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

Bill
  • 2,026
  • 9
  • 55
  • 99

1 Answers1

3

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.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • So every .Read() returns a single grid of results as the order of "exec" were sent, correct? Also, when you say .ExecuteReader, this is an extension method provided by Dapper that gives raw access, similar to DataReader present in ADO.NET? Finally, a question, DP could be used with both QueryMultiple and ExecuteReader? BTW, I watched the video on Pluralsight on Dapper, looks very good. – Bill Sep 02 '14 at 12:21
  • "yes" (well, actually it is in order of the `select` that get executed - it doesn't get to see anything more than that), "yes", and "yes" – Marc Gravell Sep 02 '14 at 12:30
  • One more question, if I am using QueryMultiple and DynamicParameters, I could pass the sql as several stored procedures calls, separated by ";", and then provide a single DynamicParameter object having all parameters for all SPs? Thanks – Bill Sep 13 '14 at 06:52
  • I finished a small component to receive any number of SPs with input parameters, and execute them all. Dapper working great so far. – Bill Sep 13 '14 at 10:32