How to use the querymultipleasync call
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi All, I've seen a couple of examples scattered over the internet and all of them are using the .Result in the end, why? u lose the whole async pros with it. if u actually wait for the IO thread to return.

I tried to call it like so:
using (var connection = new SqlConnection(ConnectionString))
{
var query = await connection.QueryMultipleAsync(
QuerySP, //only 1 stored procedure is here
queryParams,
null, null, CommandType.StoredProcedure).ConfigureAwait(false);
var result1 = query.ReadAsync<T1>();
var result2 = query.ReadAsync<T2>();
var result3 = query.ReadAsync<T3>();
var result4 = query.ReadAsync<T4>();
var result5 = query.ReadAsync<T5>();
var result = new PortalQueryResult<T1, T2, T3, T4, T5>
{
ResultSet1 = await result1.ConfigureAwait(false),
ResultSet2 = await result2.ConfigureAwait(false),
ResultSet3 = await result3.ConfigureAwait(false),
ResultSet4 = await result4.ConfigureAwait(false),
ResultSet5 = await result5.ConfigureAwait(false),
};
return result;
}
but I occasionally gets the following error: Query results must be consumed in the correct order, and each result can only be consumed once
when I change it to this:
using (var connection = new SqlConnection(ConnectionString))
{
var query = await connection.QueryMultipleAsync(
QuerySP,
queryParams,
null, null, CommandType.StoredProcedure).ConfigureAwait(false);
var result = new PortalQueryResult<T1, T2, T3, T4, T5>
{
ResultSet1 = await query.ReadAsync<T1>().ConfigureAwait(false),
ResultSet2 = await query.ReadAsync<T2>().ConfigureAwait(false),
ResultSet3 = await query.ReadAsync<T3>().ConfigureAwait(false),
ResultSet4 = await query.ReadAsync<T4>().ConfigureAwait(false),
ResultSet5 = await query.ReadAsync<T5>().ConfigureAwait(false),
};
return result;
}
it works. but performance is decreased significantly,
So what is the right way to use it?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the QueryMultipleAsync and ReadAsync usage shown in the issue, along with the behavior that requires result sets to be consumed in order. Determine the supported consumption pattern and explain why the two examples differ in behavior or performance; done means the usage guidance addresses the reported error and performance concern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend-api-design, databases
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100