开发者

Changing naming of generated files in T4

开发者 https://www.devze.com 2023-04-06 06:07 出处:网络
Is there anyway that I can change the naming of the files generated by T4 with Entity Framework Model First

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

精彩评论

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

关注公众号