Multiple Result Sets
What this page covers#
This page explains how MooDb handles multiple results from a single call.
In simple terms, one database call can return more than one thing. For example, it might return a single record, then a scalar value, then a list of rows, all from the same execution.
That single call could come from a stored procedure, from SQL text, or as part of transaction-based work.
Why this exists#
Sometimes one piece of work needs several related results back together.
For example, a single operation might need:
- one user record
- that user's orders
- a count or summary value
The simple version#
MooDb lets one execution return more than one result, then gives you a small reader API that consumes those results in order.
QueryMultipleAsync takes a synchronous callback:
var result = await db.QueryMultipleAsync( "Tests.usp_QueryMultiple_UserAndOrders", read => new UserAndOrdersResult { User = read.Single<User>(), Orders = read.List<OrderRow>() }, new MooParams().AddInt("@UserId", 1));
What the callback receives#
The callback receives IMooMultiReader.
From that object you can read the next result set as:
Single<T>()Single<T>(map)List<T>()List<T>(map)Scalar<T>()
Each call consumes the next result set in sequence.
Why this is useful#
Once MooDb has read the results, what you get back is your actual application data as hydrated POCOs or scalar values.
You do not have to keep thinking about disposing readers, managing command lifecycles, or manually coordinating result flow. That plumbing is already handled for you.
Unlike lower-level approaches, including Dapper patterns where you may need to think more directly about reader usage and disposal, MooDb keeps that infrastructure out of the way so you can stay focused on the returned data.
Important notes#
QueryMultipleAsyncuses a synchronous callback.- Results are consumed in order.
- Trying to read beyond the available result sets throws.
- The callback returns your final application object.