Click here to Skip to main content
13,048,035 members (73,019 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 19 Oct 2011

how create the Pre-Genrated Views in EF4.0

, 19 Oct 2011
Rate this:
Please Sign up or sign in to vote.
How improve performance of EF


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.

Pre-Generated Views:

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 
/mode:ViewGeneration "/inssdl:$(TargetDir)Corecon.ssdl" 
"/incsdl:$(TargetDir) Corecon.csdl" "/inmsl:$(TargetDir) Corecon.msl" 
"/outviews:$(ProjectDir) Corecon.Views.cs"

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

Step 3:

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:[^]


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ram Balak Sharma
Architect Q3 technology
India India
Ram is .Net Architect by profession and passion having 8 year experience. He has extensive experience on Microsoft Development Platform and is also Microsoft Certified Application Developer (MCAD) for Web.
Reach me at
6 Freely avaliable E-Books/

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 4 nice Pin
kiran dangar19-Oct-11 1:51
memberkiran dangar19-Oct-11 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 19 Oct 2011
Article Copyright 2011 by Ram Balak Sharma
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid