When a client aborts a request mid-stream, I keep catching TaskCanceledException bubbling out of my controller actions. My current repository pattern looks like this:
public async Task<IActionResult> GetById(int id)
{
// Shared SqlConnection
var result = await _db.QueryFirstOrDefaultAsync<Product>(
"SELECT * FROM Products WHERE Id = @id", new { id });
return Ok(result);
}
The connection opens inside a using block in the repository, yet the async call still throws on cancellation. Should I be passing a CancellationToken all the way down, or is there a Dapper-specific setting I'm overlooking? I don't want to swallow cancellations silently.
Can you answer this question?
Write Answer0 Answers