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?
I believe the concept you're looking for is 'Pre-Generated Mapping Views' â€” https://msdn.microsoft.com/en-us/data/dn469601.aspx
While searching for that feature I also came across this fairly recent relevant article â€” http://www.fusonic.net/en/blog/2014/07/09/three-steps-for-fast-entityframework-6.1-first-query-performance/
Note that in EF 5 support was added to automatically compile LINE-to-Entities queries so the compilation no longer occurred every time â€” https://msdn.microsoft.com/en-us/data/hh949853.aspx#4