Query very fast but mapping slow with dapper

dapper sql

Question

I'm using dapper for a new project and love it but I don't understand why my queries are really slow. The execution time is very fast, almost instant, but the connection stays open much longer while dapper is mapping the result to my object I guess.

Here is an example in glimpse :

Glimpse result

This query is just a SELECT on something like 15 fields with a where on the primary key, so it's really fast to execute and it doesn't return that much of data. My code to execute it is :

 using (var conn = GetConnection())
 {
    obj = conn.Get<T>(id);
 }

And the object is a very basic poco with Strings and Ints. So why do I waste 220 ms doing this while the query execution itself takes 3 ms ? Where is the difference ?

Thanks for your help !

Popular Answer

I had a similar experience with Dapper as I was trying to project from a View to an POCO object. The problem ende up being for me that I did not have a column for each property on my object, so the Convert.ChangeType() was very slow. I added a column to my View that would always return NULL, and the Query() call sped up dramatically.



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