Multiple Query

Fetch a parent and its related rows in a single round trip instead of one query per relationship.

Two flavors

ExecuteQueryMultiple takes a raw SQL statement with several SELECTs; QueryMultiple takes up to seven LINQ expressions and generates the SQL for you, returning a tuple with one item per result set.

Extracting the results

var (customers, orders) = connection.QueryMultiple<Customer, Order>(
    c => c.Id == customerId,
    o => o.CustomerId == customerId);

customer = customers.First();
customer.Orders = orders.AsList();

The raw-SQL form returns a QueryMultipleExtractor instead, and each result set is pulled out explicitly with Extract<T>() in the order the statements were written.

Per-query hints, ordering, and paging

QueryMultiple exposes hints1/hints2, orderBy1/orderBy2, and top1/top2 style arguments so each result set can be tuned independently, without hand-writing the equivalent SQL.