0

I have an application using EF code first. Unfortunately the first query takes an awful lot of time to load. When I goggled, I realized this is a quite common problem. Obviously EF needs to init/generate some views in order to work properly.

To speed this up, it's possible to generate pre-compiled views. But all solutions I found use the EF Power Tools. Unfortunately it's not possible to install the Power Tools in VS Express, at least I haven't found a way (please correct me if I'm wrong).

Is there any way to generate the views without the power tools? (maybe command line?)

Ciao, Dante

zacko
  • 339
  • 1
  • 7
  • 20

1 Answers1

1

Yes, it's possible. The actual logic to create the views is not part of EF PowerTools, but part of EF itself. EF PowerTools merely provides a nice easy-to-use menu item for it.

There are a few approaches you can take, but probably the simplest is to use a T4 template. The ADO.NET Blog has an entry on this, but there are newer ready-to-use templates available online from the VS gallery, such as this one; you may need to tweak it or look for a different one if you're not using EF6 though. Templates should install and work in any version of Visual Studio, even the Express editions, but should you encounter difficulties, as a last resort it should always be possible to unpack the downloaded file (it's a zip file) and copy the required file into your project manually.

  • 1
    Sorry for the late reply. I finally managed to install the template (had some problems with my VS installation, but should probably work for others). So I added the template to my project, the view generation was successful. But how do I use the view? Is it somehow called automatically by some magic? – zacko Jun 04 '14 at 19:35
  • @dante Yes, Entity Framework uses reflection to search the context's assembly's attributes for where the pre-generated views can be found, so the magic is activated by the `[assembly: System.Data.Entity.Infrastructure.MappingViews.DbMappingViewCacheTypeAttribute(...)]` line in the template output. –  Jun 04 '14 at 19:50
  • Is there a way to automate the view regeneration when the model changes? Perhaps via a pre-build event or similar? – Zero3 Aug 09 '18 at 22:23
  • @Zero3 I have no experience with that, but [apparently there are options](https://stackoverflow.com/questions/1646580/get-visual-studio-to-run-a-t4-template-on-every-build). –  Aug 10 '18 at 05:16