public async Task<List<T>> LoadDataAsync<T, U>(string sqlStatement, U parameters, string connectionString) {
using IDbConnection connection = new SqliteConnection(connectionString);
IEnumerable<T> rows = await connection.QueryAsync<T>(sqlStatement, parameters);
return rows.ToList();
}
var output = await _db.LoadDataAsync<PayerListModel, dynamic>(sql, new { Filter = $"%{filter}%" }, connString);
return output;
The first thing you'll want to do is use the QueryAsync
variant of the Query
method provided by Dapper, which will return a Task<IEnumerable<T>>
instead of IEnumerable<T>
.
Also as LoadData
needs to await
the response of this in order to .ToList()
it you'll need to mark the method as async
. Just for completion I've just renamed LoadData
to LoadDataAsync
, which is the convention used when you have a Task<...>
returning method.