In LinqToSql, precompiled queries are great - but it still requires me to take the compilation performance hit the first time the query is used.
I would like to 'warm up' these precompiled queries in the background when the application starts up. Obviously I can do that by calling them with some default parameters - however this results in a needless hit to the database.
Is there any way to 'warm up' the precompiled query without calling out to the database?
I have taken a look at the CompliedQuery source code but it seems many of the classes needed are sealed and/or internal...
Ok, so looking at source code for the
CompiledQuerywhich gets returned fromCompiledQuery.Compile()we can verify that the query is only actually compiled once you invoke the method for the first time:So there is no way to force the compilation without actually executing it.
However, I did find a hacky workaround for it which gives me what I need. There is a way we can execute the query thus causing the query to be precompiled without allowing the call to the database: