Using dapper async within a transaction

asynchronous dapper transactions

Question

We are currently using dapper to handle some very expensive update / delete scenarios and we are very pleased with it.

Now we have the following scenario which I want to speed up.

  • Update 1 takes about ~60 seconds.
  • Update 2 takes <1 second.

If we do this the sync way, we'll spend around 61 seconds waiting in total. Can we speed this up, to call the first update with the ExecuteAsync method, but not await it. Like so:

Connection.ExecuteAsync("Update 1", new { someValue }, Transaction, 120);
Connection.Execute("Update 2", new { someValue }, Transaction);

Notice the lack of await keyword.

This will speed things up, but is it a good idea, and will it work in a transaction? What happens when the transaction commit is hit, and the first update is still executing? Or is it a bad idea to use ExecuteAsync without await ?

Assuming update 2 is not dependent on update 1.

Popular Answer

If the first update doesn't work in the same data of the second and you don't need to wait the result, you can execute it in async mode without await. I suggest you to read this page:

http://www.joesauve.com/async-dapper-and-async-sql-connection-management/

It explain how to execute async commands with an async connection to the database, I think it can be useful for you.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why