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.
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
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.
来源:https://stackoverflow.com/questions/12790124/entity-framework-5-stopped-running-t4-templates-files-on-save