Is it possible to precompile the EF query so that it won't need to be compiled by the app when it is used for the first time?

I have a ton of intricate queries that take some time to process using L2E. For instance, Sql Server profiler indicates an execution time of about 300 ms for one of the benchmarked queries, whereas my PC (a Xeon Quad Core 2.6 GHz with 8GBs of RAM) really completes this query in about 4.5 s. This indicates that my PC spends approximately 0.5 seconds waiting for data to arrive before spending approximately 4 seconds compiling, executing, and reading the query (which is 4 records only). That's a long time, especially since ToListAsyns() won't let the user interface take over until the actual database query has been received, which means that for the entire 4 seconds, my program "hangs." Using Task.Run() in place of ToListAsync is one method to get past this, however doing so will just allow my application to display a waiting icon; there will still be a 4s delay.

This may result in the user having to wait for the query compilation to complete for up to 10 seconds on some older PCs, which is not ideal. Anyone with knowledge on how to precompile all of my queries such that they run quickly even the first time?

4/24/2015 2:09:40 PM

Popular Answer

Pre-Generated Mapping Views, I think, is the idea you're seeking for.

While looking for that feature, I also found this current, pertinent article,

Note that LINE-to-Entities queries are now automatically compiled in EF 5, eliminating the need for manual compilation.

4/24/2015 8:28:45 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow