EF6/Code First: Super slow during the 1st query, but only in Debug

entity-framework entity-framework-6 visual-studio-2013


The issue is that if I compile and run the exe program it takes about 15 seconds to perform the first query (that's acceptable, since I'm still working on the pre-generated views). I'm using EF6 rc1 with Code First strategy, without precompiled views. However, it takes over 2 minutes BEFORE launching the first query if I use Visual Studio 2013 Preview to debug the exact same application.

Dim Context = New MyEntities()
Dim Query = From I in Context.Itens '' <--- The debug takes 2 minutes in here
Dim Item = Query.FirstOrDefault()

Is it possible to cut this extra time off? Am I doing this incorrectly?

P.S. : The context itself is not difficult; it is just packed with more than 200 tables.

Edit: It was discovered that the issue is that the EF seems to be producing the Views during debug time while disregarding the pre-generated ones. I found the following property in the EF source code:

IQueryProvider IQueryable.Provider
            return _provider ?? (_provider = new DbQueryProvider(

is the location where time is spent. But given that only debugging costs time, this is odd. Am I overlooking anything here?

Edited to add more relevant information to the query: I discovered that the 'desenv.exe' process is taking up a lot of time using the Process Monitor (by Sysinternals). To be more precise, a "Thread Exit" is taking up time. The Thread Exit stack is repeated 36 times. I'm not sure if this information will be of any assistance, but I saved a ".cvs" file with the stack, and this is his body: [...] (edit: the ".cvs" body has been removed; if anyone truly believes it will be useful, please feel free to submit it again in the comments.)

Edit: VS2013 Ultimate and Entity Framework 6 RTM were installed. utilized the Entity Framework Power Tools Beta 4 to generate the Views after installing them. Nothing has altered... Running the executable only takes 20 seconds, however starting debugging requires 120 seconds.

Edit: A little project called http://sdrv.ms/16pH9Vm was made to imitate the problem. Simply launch the project through the.exe and within the environment, click the button, and compare the loading times.

10/22/2013 3:24:39 PM

Accepted Answer

10/31/2013 9:14:46 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