Dapper - Result Multi-Result

Description

QueryMultiple method is an extension method which can be called from any object of type IDbConnection. It can execute multiple queries within the same command and map results.

  1. string sql = "SELECT * FROM Invoice WHERE InvoiceID = @InvoiceID; SELECT * FROM InvoiceItem WHERE InvoiceID = @InvoiceID;";
  2. using (var connection = My.ConnectionFactory())
  3. {
  4. connection.Open();
  5. using (var multi = connection.QueryMultiple(sql, new {InvoiceID = 1}))
  6. {
  7. var invoice = multi.Read<Invoice>().First();
  8. var invoiceItems = multi.Read<InvoiceItem>().ToList();
  9. }
  10. }