Last post May 04, 2018 03:02 AM by Nan Yu
May 03, 2018 02:00 PM|rajemessage|LINK
I have noticed an article "Pre-Generated Mapping Views", which was not clear. please send me some article for
vs 2013 and ef6(onwards).
May 03, 2018 05:19 PM|ryanbesko|LINK
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)
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).
May 04, 2018 03:02 AM|Nan Yu|LINK
Hi rajemessage ,
Mapping view generation is a significant part of the overall cost of executing the first query, the Entity Framework enables you to pre-generate mapping views and include them in the compiled project. For more information, see Performance
Considerations (Entity Framework).
As @Ryan suggested , you could create Mapping Views with the EF Power Tools . Please refer to below article which provides the detail steps with code sample :