From 223dcda0cbb3c2fa1e46adf04953afd2162f88b1 Mon Sep 17 00:00:00 2001 From: BillWagner Date: Tue, 2 May 2017 16:21:21 -0400 Subject: [PATCH] add back the async state machine Because of the using blocks, these one line methods need the async modifier so that the that async state machiner is created. Otherwise, if the method does not complete synchronously, the connection is closed before the database has returned its results. --- .../Ordering.API/Application/Queries/OrderQueries.cs | 8 ++++---- .../Ordering/Ordering.API/Controllers/OrdersController.cs | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs b/src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs index afcfc71b5..e51cf04ce 100644 --- a/src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs +++ b/src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs @@ -44,13 +44,13 @@ } } - public Task> GetOrdersAsync() + public async Task> GetOrdersAsync() { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); - return connection.QueryAsync(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total + return await connection.QueryAsync(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total FROM [ordering].[Orders] o LEFT JOIN[ordering].[orderitems] oi ON o.Id = oi.orderid LEFT JOIN[ordering].[orderstatus] os on o.OrderStatusId = os.Id @@ -58,13 +58,13 @@ } } - public Task> GetCardTypesAsync() + public async Task> GetCardTypesAsync() { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); - return connection.QueryAsync("SELECT * FROM ordering.cardtypes"); + return await connection.QueryAsync("SELECT * FROM ordering.cardtypes"); } } diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs index 05a9cd193..20c1e023f 100644 --- a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs +++ b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs @@ -68,8 +68,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers [HttpGet] public async Task GetOrders() { - var orders = await _orderQueries - .GetOrdersAsync(); + var orderTask = _orderQueries.GetOrdersAsync(); + + var orders = await orderTask; return Ok(orders); }