Dapper - QueryMultiple

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. }

Parameters

The following table shows different parameter of an QueryMultiple method.

NameDescription
sqlThe query to execute.
paramThe query parameters (default = null).
transactionThe transaction to use (default = null).
commandTimeoutThe command timeout (default = null)
commandTypeThe command type (default = null)