Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 5 stopped running T4 templates files on save

At work we just upgraded to Entity Framework 5. Our EDMX file now has a couple other nodes beneath it:

EntityContainer.Context.tt

which contains the generated DbContext object and

EntityContainer.tt

which contains the entities themselves.

For a short period, adding an entity in EF was automatically regenerating the tt (T4 Templates) when we would save the EDMX file. Now all of a sudden we have to right-click the T4 templates and select "Run Custom Tool" to get them to regenerate the .cs files for the context or entities.

Any ideas how this might have happened?

Update

In the EDMX the property "Transform Related Text Templates On Save" is set to true and the problem is still happening.

like image 807
Chev Avatar asked Jan 16 '23 09:01

Chev


2 Answers

Is your EDMX in a sub-folder of your project? If so, the good news is that you didn't do anything wrong. The bad news is that this is a known issue...check my blog post about it. http://thedatafarm.com/blog/data-access/watch-out-for-vs2012-edmx-code-generation-special-case/.

Two work arounds for the time being:

1) move the edmx into the main project folder 2) explicitly force the code gen as needed

like image 83
Julie Lerman Avatar answered Jan 30 '23 22:01

Julie Lerman


There is actually another workaround option. I discovered this error because I upgraded an EF 4 EDMX to EF 5 by adding EF 5.x DbContext Generator to the project, which added T4 templates to the existing EDMX.

However, in the project file it did not mark them as DependentUpon the EDMX file so they did not appear under the EDMX node. Instead they appeared side-by-side with the EDMX in the folder. T4 generation worked fine until I manually went in and added the DependentUpon nodes in the project file.

Observe: http://www.youtube.com/watch?v=-boB5GhqfUI

like image 38
Chev Avatar answered Jan 31 '23 00:01

Chev