If you are using the Entity Framework (EF) then you need to understand how a query is executed in the Entity Framework else you will face the performance issues.
In order to better understand the performance of queries in the Entity Framework, it is helpful to understand the operations that occur when a query executes against a conceptual model and returns data as objects.
This is the most expensive operation (it takes over 50% of the initial query) is View Generation Before the Entity Framework can execute a query against a conceptual model or save changes to the data source, it must generate a set of local query views to access the database. The views are part of the metadata which is cached per application domain. If you create multiple object context instances in the same application domain, they will reuse views from the cached metadata rather than regenerating them. Because view generation is a significant part of the overall cost of executing a single query, the Entity Framework enables you to pre-generate these views and include them in the compiled project
Pre-generated views are validated at run time to ensure that they are consistent with the current version of the model and mapping files.
There are three steps how we implement the pre generated views in our application?
Select the Priority window of your EDMX and change the Metadata Artifact Processing to Copy to Output Directory. And build the Project.
Step2:To add view in the project
1. Go the Solution explorer and right click on Project
2. select the Project Properties In Properties page select the build event tab;
3. Paste the following code with remove the line break in the Pre-build Event Command Line
"%windir%\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe" /nologo /language:CSharp
"/incsdl:$(TargetDir) Corecon.csdl" "/inmsl:$(TargetDir) Corecon.msl"
Now build the Project.This will generates the view file Corecon.View.cs
In Solution Explorer, right-click the project name and select Add Existing Item.
The Add Existing Item dialog box appears. Navigate to the project's root folder and select the Corecon.View.cs file. Click Add.
Now build the solution
To re-add mapping and model files as embedded resources for ASP.NET projects.
1.On the Project menu, click Add Existing Item.
2.Browse to the output directory for the project, select Corecon.csdl, and then click OK.
3.In Solution Explorer, select the added file.
4.In Properties, set Build Action to Embedded Resource.
5.Repeat steps 1 through 3 for the Corecon.ssdl file and the Corecon.msl file.
6.In Solution Explorer, double-click the App.config file and then modify the Metadata parameter in the connection String attribute based on one of the following formats:
For more Details: