Dapper official translation Tutorial 8: QueryMultiple Dapper method of (turn)

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 

 

  1.  
    // execute multiple queries
  2.  
    string sql = "SELECT * FROM Invoice WHERE InvoiceID = @InvoiceID; SELECT * FROM InvoiceItem WHERE InvoiceID = @InvoiceID;";
  3.  
     
  4.  
    using (var connection = My.ConnectionFactory())
  5.  
    {
  6.  
    connection.Open();
  7.  
     
  8.  
    //Inquire
  9.  
    using (var multi = connection.QueryMultiple(sql, new {InvoiceID = 1}))
  10.  
    {
  11.  
    // Read <Type> mapping result set
  12.  
    var invoice = multi.Read<Invoice>().First();
  13.  
    var invoiceItems = multi.Read<InvoiceItem>().ToList();
  14.  
    }
  15.  
    }

 

Guess you like

Origin www.cnblogs.com/LiZhongZhongY/p/10991670.html