Grimson
Grimson

Reputation: 572

Dapper Query vs QueryMultiple performance

I am currently querying 8 times using Query<> (8 times because I have to convert some columns into JSON and sometimes separately) to generate one complete result set required. However, I was wondering if it is possible to increase the performance by using QueryMultiple. I have a hypothesis that QueryMultiple can query all those tables at the same time so I don't have to wait for every single query to complete.

I have one other option. It is use *Async versions of the methods.

However, I can't implement QueryMutiple without significantly changing the code. Should I use QueryMutiple or the *Async versions of the regular methods? What is the tradeoff between the two alternatives and which one should I be using?

Upvotes: 2

Views: 3614

Answers (1)

Namoshek
Namoshek

Reputation: 6544

QueryMultiple will perform all queries in one batch resulting in only one round trip to the database while executing eight individual queries with Query<> will also result in eight round trips.

If you execute all your queries sequentially (without using the Async methods), you are wasting a lot of time because the database will idle between returning query results and receiving the next query by your application. Using Async may improve the performance because your application can send another query to the database while the previous one is being executed. Using Async will still result in eight round trips and batches with one single query though, meaning that using QueryMultiple yields (in theory) the best performance in the end.

Upvotes: 5

Related Questions