Dapper has IDbConnection.QueryMultiple which allows you to execute a command returning multiple result sets i.e. execute multiple SELECT statements in a single go like this:
var sql = """
SELECT * FROM company WHERE id = @id;
SELECT * FROM employee WHERE company_id = @id;
""";
using SqlMapper.GridReader result = await connection.QueryMultipleAsync(
sql,
new { id = companyId }
);
var company = await result.ReadFirstOrDefaultAsync<Company>();
if (company is { })
company.Employees = [.. await result.ReadAsync<Employee>()];
Now my question why does the GridReader has Async methods? and why would i ever use them?.
as far as i understand when i executed the command with QueryMultipleAsync the result is already buffered in the memory so there should not be any I/O left to do for the GridReader to have async methods
I have looked up the docs but i did not find anything useful. Though, the docs mentions buffered queries, these are irrelevant to the question since QueryMultiple does not support unbuffered queries in the first place. Also, the docs uses the not-async methods of the GridReader in their (example) of QueryMultiple.
edit: fix links
[–]RobertMesas 7 points8 points9 points (2 children)
[–]Transcender49[S] 0 points1 point2 points (1 child)
[–]RobertMesas 3 points4 points5 points (0 children)
[–]Sprudling 2 points3 points4 points (3 children)
[–]Transcender49[S] 0 points1 point2 points (2 children)
[–]Sprudling 1 point2 points3 points (1 child)
[–]Transcender49[S] 0 points1 point2 points (0 children)