Created
May 29, 2019 04:29
-
-
Save mikependon/44e39494f2ed8ad5f7ef926b02802089 to your computer and use it in GitHub Desktop.
IDbConnection (ExecuteQueryMultiple)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var connection = new SqlConnection(connectionString)) | |
{ | |
// Call the method by passing multiple statements | |
var extractor = connection.ExecuteQueryMultiple("SELECT * FROM [dbo].[Customer] WHERE Id = @CustomerId; " + | |
"SELECT * FROM [dbo].[Order] WHERE CustomerId = @CustomerId; " + | |
"SELECT GETUTCDATE() AS RetrievedDateTimeUtc;", | |
new { CustomerId = 10045 }); | |
// Extract the results | |
var customer = extractor.Extract<Customer>().FirstOrDefault(); | |
var orders = extractor.Extract<Order>().ToList(); | |
var retriveDateTime = extractor.Scalar<DateTime>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment