Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Async Await keywords with Dapper

I want to use a micro-orm and decided to go with Dapper.

But can't seem to find any mentions of it supporting the new async/await syntax. Async queries are important for me.

Can someone provide a code example of an async query being made with Dapper using the await keyword ?

like image 828
Yaron Levi Avatar asked Sep 14 '14 12:09

Yaron Levi


People also ask

What is the purpose of async await keywords?

The async keyword turns a method into an async method, which allows you to use the await keyword in its body. When the await keyword is applied, it suspends the calling method and yields control back to its caller until the awaited task is complete. await can only be used inside an async method.

Is Dapper async?

So far, we performed all synchronous operations, but Dapper also fully supports async versions of all of the primary methods.

How does the await keyword work in C#?

The await operator suspends evaluation of the enclosing async method until the asynchronous operation represented by its operand completes. When the asynchronous operation completes, the await operator returns the result of the operation, if any.


1 Answers

Dapper when targeting .NET 4.5 has full support for TPL usage, via the methods ending in *Async - QueryAsync etc. Specifically, the .NET 4.5 build includes this extra set of methods

like image 125
Marc Gravell Avatar answered Sep 23 '22 11:09

Marc Gravell