As requested by the community, we need to add an additional argument to the Extract and Scalar method of the QueryMultipleExtractor class.
The call below is moving to the next result after calling the Extract.
using (var connection = new SqlConnection(connectionString))
{
var commandText = "SELECT Id, Name FROM [dbo].[Customer] WHERE Id = @CustomerId; SELECT * FROM [dbo].[Order] WHERE CustomerId = @CustomerId;";
using (var extractor = connection.ExecuteQueryMultiple(commandText, new { CustomerId = 10045 }))
{
var customer = extractor.Extract<Customer>().FirstOrDefault(); // <-- This does not moves to the next result
var orders = extractor.Extract<Order>().AsList(); // <-- In the 2nd position
// Do the stuffs for the 'customer' and 'orders' here
}
}
By passing a value of false to the argument isMoveToNextResult, then the data reader will not move the pointer.
using (var connection = new SqlConnection(connectionString))
{
var commandText = "SELECT Id, Name FROM [dbo].[Customer] WHERE Id = @CustomerId; SELECT * FROM [dbo].[Order] WHERE CustomerId = @CustomerId;";
using (var extractor = connection.ExecuteQueryMultiple(commandText, new { CustomerId = 10045 }))
{
var customer = extractor.Extract<Customer>(false).FirstOrDefault(); // <-- This moves to the next result
extractor.NextResult(); // <-- Manually moving to the next result
var orders = extractor.Extract<Order>().AsList(); // <-- In the 2nd position
// Do the stuffs for the 'customer' and 'orders' here
}
}
The same scenario is the same for the Scalar method, and also to their corresponding Async methods. FYI: @cleverguy25
As requested by the community, we need to add an additional argument to the
ExtractandScalarmethod of the QueryMultipleExtractor class.The call below is moving to the next result after calling the
Extract.By passing a value of
falseto the argumentisMoveToNextResult, then the data reader will not move the pointer.The same scenario is the same for the
Scalarmethod, and also to their correspondingAsyncmethods. FYI: @cleverguy25