I'm working on an MVC 5 application that uses Entity Framework 6.1.3. I'm trying to optimize the first call, which usually takes 1-4 seconds, by pre-generating the views. I understand why this is happening, but I feel like I'm missing an important step somewhere.
My current test runs the same function five times to pulls a collection of objects from my DB using EF. When I run this with 'Embed in Output Directory' set in my edmx I get the following results:
**
**
I expect this since EF is generating the local views to access the database...
When I switch to 'Copy to Output Directory', double check that my files are being copied to the bin folder and my connection string has been updated, and then run the same test I get similar results:
**
**
No change in the first call, which is strange. I added EF Power Tools, right-clicked on my edmx => Entity Framework => Generate Views. A 'Model1.View.cs' file was created with string for each of my tables/views, so I felt like I was on the right path. When I ran the test again I got the same results. Putting a breakpoint in each method of the newly generated 'Model1.View.cs' file shows that it's never being hit.
Am I missing an important step here? How do I tell EF to use the file that was created by EF Power Tools, or how do I make the Copy to Output Directory work as I've read online?
As far as I remember EF Power Tools was not updated to support EF6. If you are sure this is view generation that is causing the issue you could either use the view generation T4 template or the interactive pre-gegnerated views (yes, I am the creator of both). You can find more details on how to use the T4 template in this post. Interactive Pre-Generated views are described here.
However, view generation in EF6 was greatly improved and is only a problem for bigger models or when complex hierarchies are involved. I assume the bottleneck you are seeing is not caused by view generation but by model building. Take a look at this post by EF team that talks a little bit about improving startup performance by generating native images. You may also want to take a look at Performance Consideration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With