Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDbCommand missing ExecuteReaderAsync

Tags:

I'm using .NET Core 2.0. I've got the following function that calls IDbCommand.ExecuteReader

public async Task<IEnumerable<Widget>> ReadAllAsync(
    System.Data.IDbConnection databaseConnection,
    System.Data.IDbTransaction databaseTransaction)
{
    var commandText = "SELECT WidgetId, Name FROM Widget";

    // _databaseCommandFactory.Create returns an IDbCommand
    var command = this._databaseCommandFactory.Create(databaseConnection, databaseTransaction, commandText);

    using (var dataReader = command.ExecuteReader())
    {
        // iterate through the data reader converting a collection of Widgets (`IEnumerable<Widget>`)
    }
}

I get a warning

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

I was thinking about converting the command.ExecuteReader() statement to await Task.Run(() => command.ExecuteReader()) as advised in the warning. But I'm not sure this is the correct approach, I believe Task.Run(...) is for doing CPU based work. This is primarily IO work.

So my questions are

  1. Is Task.Run(...) the correct approach?
  2. If not, is there another solution?
  3. Or should I just ignore the warning for now and wait until ExecuteReaderAsync gets added to the IDbCommand interface? (is there a plan for this?)