Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.

Interactive Pre-Generated Views for Entity Framework 6 - what is it?

Entity Framework is an open source object-relational mapper from Microsoft which simplifies working with databases by eliminating the data access layer that would otherwise be needed to send queries/commands to the database and interpret the results. Entity Framework is not tied to any specific database but is using a provider model that allows plugging-in various databases by writing an EF provider for a given database. To be able to handle this, Entity Framework builds internally a set of views that describe the database in the database agnostic way. All further processing (queries, updates etc.) EF does is performed against these views. Generating views however can be costly and might impact start up time of the application. This can be worked around by generating views at design time e.g. by using view generation templates or EF Power Tools. Views generated this way are typically static and may affect the build time of the project as well as the size of the application. An alternative is a solution where views are created dynamically only when needed (i.e. views don't exist or are out dated) and then persisted and made available for use by other instances of the same application (be it running in parallel or the same application after a restart). This is exactly the problem Interactive Pre Generated Views project is trying to solve.

This project was moved from

You may still find some useful information there:

How to get it?

Interactive Pre Generated Views project ships on NuGet. You just need to add the package to your project and set up a factory that generates views (see below).

How to use it?

Currently views can be stored either in a file on the disk or in the database. Regardless of the mechanism used to stored views the first step is to set up a factory that generates views. Note that this has to be done before sending the first query/command (including SaveChanges()) to the database since any of the operations will trigger view generation (for instance it can be done in the static constructor of the class that contains the Main method).

The factory that generates views and persist them in a file can be registered as follows:

using (var ctx = new MyContext())
            new FileViewCacheFactory(@"C:\MyViews.xml"));

The factory that generates views and persist them in a database (note - currently only Sql Server is supported but other databases can be added very easily) can be registered as follows:

using (var ctx = new MyContext())
            new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString));

Note that the factory that generates and persists views in the database will create a table in the target database for storing views if the table does not exist. If the table cannot be created (e.g. the database does not exist or due to insufficient permissions) an exception will be thrown.


I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook)


No description, website, or topics provided.







No packages published