using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (var multiQuery = connection.QueryMultiple("SELECT * FROM Customers; SELECT * FROM Orders;")) { var customers = multiQuery.Read(); var orders = multiQuery.Read (); // do something with customers and orders } }
using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (var multiQuery = connection.QueryMultiple("SELECT COUNT(*) FROM Customers; SELECT AVG(OrderTotal) FROM Orders;")) { var customerCount = multiQuery.ReadSingleThis example shows how to execute two aggregate queries against a SQL Server database in a single round trip and read the results into two separate variables. The package library used in these examples is the Dapper package, which is a lightweight ORM (Object Relational Mapping) that provides easy data access for .NET applications.(); var orderAverage = multiQuery.ReadSingle (); // do something with customerCount and orderAverage } }