Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Created Issue: SqlQuery for non-mapped types is slower than for mapped types [746]

$
0
0
When using DbContext to perform queries using SqlQuery (context.Database.SqlQuery<T>) then queries are significantly slower when T is not included as a DbSet on the context.

It appears that when mapping the data to the type we are working out the mapping for every query instead of caching it. Calling CreateColumnMapFromReaderAndClrType for every query causes reflection over every property on the type. The more properties on the type the slower the queries become.

A quick test on my machine showed that caching the CollectionColumnMap will take the execution time to the same as executing a mapped type, though this may not be the best way to go about fixing this.

The other issue I noticed is that even when we are using the generic SqlQuery method, EF will still use reflection to execute the generic version of the ExecuteStoreQuery command instead of executing the generic version directly. I didn't try and profile this to see if fixing it would cause an improvement, but it seems like it should. When the type is included in the context a different path is executed that bypasses this reflection code, so it would only effect queries for types not included on the context.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>