Is there a way to precompile the EF query, so that the app has no need to compile it (even if it is executed for the first time)?

I have lots of complex queries which, when using L2E take some time to execute. For example, for one query that I benchmarked Sql Server profiler reports approx 300ms execution time, but actually this query is completed after approx 4.5s on my PC (Xeon Quad Core 2.6 GHz with 8GBs of RAM. This means that my PC is waiting for data to arrive approx 0.5s, and spends approx 4s to compile and execute query, and finally read the data on my PCs (which is 4 records only). Thats a lot of time, especially since ToListAsyns() will not return control to the UI until the actual query is sent to database, so that means that all 4 seconds my app "hangs". One way around this is to use Task.Run() instead of ToListAsync, but that will only allow my application to show some waiting sign, there will still be a 4s delay.

On some older PCs this could mean that user will be waiting for 10s for query compilation, which is not something that is desirable. So, anyone knows how can I precompile all my queries, so that even the first time they are executed without delay?

4/24/2015 2:09:40 PM

Popular Answer

I believe the concept you're looking for is 'Pre-Generated Mapping Views' —

While searching for that feature I also came across this fairly recent relevant article —

Note that in EF 5 support was added to automatically compile LINE-to-Entities queries so the compilation no longer occurred every time —

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