Dapper official translation Tutorial 8: QueryMultiple Dapper method of
QueryMultiple method described
QueryMultiple method is an extension method, it can be called IDbConnection object, you can execute a query, and mapped to the result. Can achieve a lot of queries with a query, and using a strongly typed read the result set.
The method may be used parameter QueryMultiple
Name | Description |
---|---|
sql | check sentence |
param | parameter |
transaction | Whether to open the transaction |
commandTimeout | Timeout period |
commandType | Command Type |
Examples
-
// execute multiple queries
-
string sql = "SELECT * FROM Invoice WHERE InvoiceID = @InvoiceID; SELECT * FROM InvoiceItem WHERE InvoiceID = @InvoiceID;";
-
-
using (var connection = My.ConnectionFactory())
-
{
-
connection.Open();
-
-
//Inquire
-
using (var multi = connection.QueryMultiple(sql, new {InvoiceID = 1}))
-
{
-
// Read <Type> mapping result set
-
var invoice = multi.Read<Invoice>().First();
-
var invoiceItems = multi.Read<InvoiceItem>().ToList();
-
}
-
}