Click here to Skip to main content
15,910,773 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi there,

I have an entity model built using EF4.1 Code First. To improve performance I have pre-compiled the views that EF normally generates at runtime. This works fine when I run locally or publish to our test server from visual studio. However, when I build the project using a TFS team build on a build server, I get the following exception when try and query the entity model:

The mapping and metadata information for EntityContainer 'X' no longer matches the information used to create the pre-generated views.

I was wondering if anyone else has had similar issues, and whether there is a way around this. As far as I know pre-compiled views are not machine specific, so the issue may very well lie with either TFS or msbuild.

Thanks in advance for any help

Ryan
Posted
Updated 4-Dec-16 15:14pm
Comments
Ryan Gamal 18-Jul-11 11:44am    
This is currently under investigation by the product team @ Microsoft...

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/f28eb9da-8e76-46c0-993f-10be01081fed

I would think that it's almost certainly a build issue. Doing pre-compiled views requires generating source files, which has traditionally been a weak spot of build environments.

Three things need to happen in exactly right order for it to work: (1) metadata artifacts need to be copied to the output directory, (2) edmgen has to pick them up and build X.Views.cs (or X.Views.vb), and (3) CS compiler has to build X.Views.cs generated during step 2. I would examine the build logs to see if things happen in the right order.

One issue that comes up repeatedly is inclusion of generated artifacts in the source control. Sometimes, plug-ins do it for you when you add generated sources to your project. If your X.Views.cs (or X.Views.vb) has been added to source control, you need to remove it.

Another thing you need to check is that the source directory to which X.Views.cs is written allows writing. It's near certainty that it's writable on your development workstation, but TFS may be a completely different story.

Good luck!
 
Share this answer
 
Comments
Ryan Gamal 13-Jun-11 5:27am    
Thanks for the info. Because I'm using EF4.1 Code First approach, the metadata artifacts don't in fact exist at compile time. Rather than using edmgen in the build, I am using the visual studio EF power tools to generate the pre-compiled view and then this is added to the project at design time.

Thus, the pre-compiled views are generated at design time only and are not regenerated by the team build.
mbradea 1-Jun-13 15:47pm    
Did you find any solution when using Code First models?
I have the same problem. Sometimes it works and sometimes it doesn't. Wasting hours of time trying to fix it.
 
Share this answer
 
Run the script for generation of updated view

%windir%\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe /nologo /language:CSharp /mode:ViewGeneration "/inssdl:[Your Path for the files in visual studio]\obj\Debug\edmxResourcesToEmbed\yourproject.ssdl" "/incsdl:[Your Path for the files in visual studio]\obj\Debug\edmxResourcesToEmbed\yourproject.csdl" "/inmsl:[Your Path for the files in visual studio]\obj\Debug\edmxResourcesToEmbed\yourproject.msl" /outviews:[Your Path for the files in visual studio]\yourproject.Views.cs
 
Share this answer
 
Right, Click to the project folder where you have DBContext class. Then select the Entity framework and click on Generate View. Each time you create new model you need to repeat the process
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900