QueryMultiple方法也是一个扩展方法,可以被IDbConnection对象调用,可以执行查询语句,并且映射到结果。可以实现多条查询语句一起查询,并且使用强类型读取结果集。
Name | Description |
---|---|
sql | 查询语句 |
param | 参数 |
transaction | 是否开启事务 |
commandTimeout | 超时时长 |
commandType | 命令类型 |
//执行多条查询
string sql = "SELECT * FROM Invoice WHERE InvoiceID = @InvoiceID; SELECT * FROM InvoiceItem WHERE InvoiceID = @InvoiceID;";
using (var connection = My.ConnectionFactory())
{
connection.Open();
//查询
using (var multi = connection.QueryMultiple(sql, new {InvoiceID = 1}))
{
//Read<Type>映射结果集
var invoice = multi.Read<Invoice>().First();
var invoiceItems = multi.Read<InvoiceItem>().ToList();
}
}