1

From this question it seems that Npgsql doesn't support async so I start to replace all my calls by synchronous ones, but the answer is very old and I would like to know if it still applies AsyncQuery with postgresql and dapper using npqsql

This is how most of my code looks like

using Dapper;

using(var connection = new NpgsqlConnection(connectionString))
{
    var myResult = connection.QueryAsync<MyModel>(
         "SELECT * FROM my_model_table WHERE id = @id"), new { id });
}
geckos
  • 5,687
  • 1
  • 41
  • 53
  • 1
    From the source [here](https://github.com/npgsql/npgsql/blob/main/src/Npgsql/NpgsqlCommand.cs/#L1103) it seems it has been fixed in NpgSqlCommand. – Palle Due Oct 26 '20 at 06:49

1 Answers1

3

Yes, recent versions of Npgsql are fully asynchronous. Calling async ADO.NET APIs will properly perform async network operations.

Shay Rojansky
  • 15,357
  • 2
  • 40
  • 69
  • It should be noted that while Npgsql implements `async` methods, it is does not allow `asynchronous` command execution within the same connection. – Tronald Mar 30 '21 at 18:35
  • Concurrent use of the same connection indeed isn't allowed (i.e. connection isn't thread-safe), regardless of whether I/O is being done synchronously or asynchronously. – Shay Rojansky Mar 30 '21 at 18:52