Search code examples
entity-frameworkcode-firstprecompiled-views

EF code first: Generate pre-compiled view (VS 13 express)


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


Solution

  • 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.