Skip to content

Commit 223dcda

Browse files
committed
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.
1 parent d97ae6d commit 223dcda

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,27 @@ FROM ordering.Orders o
4444
}
4545
}
4646

47-
public Task<IEnumerable<dynamic>> GetOrdersAsync()
47+
public async Task<IEnumerable<dynamic>> GetOrdersAsync()
4848
{
4949
using (var connection = new SqlConnection(_connectionString))
5050
{
5151
connection.Open();
5252

53-
return connection.QueryAsync<dynamic>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
53+
return await connection.QueryAsync<dynamic>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
5454
FROM [ordering].[Orders] o
5555
LEFT JOIN[ordering].[orderitems] oi ON o.Id = oi.orderid
5656
LEFT JOIN[ordering].[orderstatus] os on o.OrderStatusId = os.Id
5757
GROUP BY o.[Id], o.[OrderDate], os.[Name]");
5858
}
5959
}
6060

61-
public Task<IEnumerable<dynamic>> GetCardTypesAsync()
61+
public async Task<IEnumerable<dynamic>> GetCardTypesAsync()
6262
{
6363
using (var connection = new SqlConnection(_connectionString))
6464
{
6565
connection.Open();
6666

67-
return connection.QueryAsync<dynamic>("SELECT * FROM ordering.cardtypes");
67+
return await connection.QueryAsync<dynamic>("SELECT * FROM ordering.cardtypes");
6868
}
6969
}
7070

src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public async Task<IActionResult> GetOrder(int orderId)
6868
[HttpGet]
6969
public async Task<IActionResult> GetOrders()
7070
{
71-
var orders = await _orderQueries
72-
.GetOrdersAsync();
71+
var orderTask = _orderQueries.GetOrdersAsync();
72+
73+
var orders = await orderTask;
7374

7475
return Ok(orders);
7576
}

0 commit comments

Comments
 (0)