User2053451246 posted
If you use Entity Framework, by default every time your application starts it will have to spend time to compile your EF models into SQL code that is sent to the database to get results. By per-compiling the view code you save on the time it takes
for your application to start.
For instance if you were to use
https://marketplace.visualstudio.com/items?itemName=EntityFrameworkTeam.EntityFrameworkPowerToolsBeta4 it has a feature that allows you to right-click a DB Context .cs file and generate another .cs file with all of the per-compiled views. (The page
does say beta but I used it for several years; the non-beta one available today is not available for VS 2013). It generates this for a table called State:
private static DbMappingView GetView29()
{
return new DbMappingView(@"
SELECT VALUE -- Constructing State
[CodeFirstDatabaseSchema.State](T1.State_StateId, T1.State_Name, T1.State_Description)
FROM (
SELECT
T.StateId AS State_StateId,
T.Name AS State_Name,
T.Description AS State_Description,
True AS _from0
FROM QuotingContext.States AS T
) AS T1");
}
The file will be called YourContextName.Views.cs. EF will automatically use the file at startup because of it's name (by convention).