开发者

Changing naming of generated files in T4

Is there anyway that I can change the naming of the files generated by T4 with Entity Framework Model First

I have tried to change the output extension to this:

<#@ output extension=".Generated.cs"#>

that changed the name of the Model1.cs file to Mode1.Generated.cs but all my entities are still in fi开发者_Go百科les named category.cs, Issue.cs etc. What I want is the entity classes still to be named:

Category
Issue
..

but the containing files to followed the naming pattern:

Category.Generated.cs
Issue.Generated.cs
...


Setting output directive will only configure the main file generated by the template. T4 templates with default custom tool generates only single file. These EF templates handles multiple file generation by their own so you must visit the T4 code and search for snippets like:

// Emit Entity Types
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{
    fileManager.StartNewFile(entity.Name + ".cs");
    ...

And

foreach (ComplexType complex in ItemCollection.GetItems<ComplexType>().OrderBy(e => e.Name))
{
    fileManager.StartNewFile(complex.Name + ".cs");

Modify names of started files as you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜