I have a query that takes a little time on first run. All subsequent executions are very fast (even with different data). I believe that the first execution of EF automatically compiles the request (building a query plan, blah blah blah), and the second call uses the compiled version. This is normal except for the first user. This bad juice is screwed. On a bad day, EF execution will be 2 minutes (with 71ms it actually talks to SQL Server - it is checked using SQL Server Profiler.)
I went ahead and precompiled the views, which repaired the initial caching a bit.
Basically the query looks something like this:
dataSource.Component .Include(t => t.Table1) ... 37 tables later ... .Include(t => t.Table38) .Where(n=>n.Id == id).First()
Now I can not bother with the data model. But for the background, basically, each table is a βformβ.
The output of SQL Server Profiler is basically a large UNION with tables, but the execution is very fast, so I don't think the problem is with the layout / keys of the table ...
Besides warming EF on startup, I hope I don't have something basic? It seems that the pipeline for compiling the request is a pretty black box? Is there a way to connect to the query preparation process to find out what is happening? (Maybe something less decisive than capturing the source .. :)
source share