重命名实体框架T4模板生成的类名称? [英] Rename Entity Framework T4 Template Generated Class Names?

查看:76
本文介绍了重命名实体框架T4模板生成的类名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常多的表的数据库,不幸的是没有标准的约定命名:

I have a database with a very large number of tables which unfortunately have been named with no standard convention whatsoever:


  • TableName

  • anotherTableName

  • YETANOTHERTABLENAME

  • Garbage_Table

  • TableName
  • anotherTableName
  • YETANOTHERTABLENAME
  • Garbage_Table

我正在使用具有标准T4代码生成模板的实体框架在C#中创建POCO类

I am using Entity Framework with the standard T4 Code Generation template to create the POCO classes in C#

有没有最好的做法让我结合我自己的惯例在C#应用程序中命名这些表,而不用在SQL中触摸任何东西?自动生成的类看起来像:

Is there a best practice I can follow which lets me incorporate my own convention to name these tables in the C# app without having to touch anything in SQL? The auto-generated classes look like:


  • TableNames.cs

  • anotherTableNames.cs

  • YETANOTHERTABLENAMEs.cs

  • Garbage_Tables.cs

  • TableNames.cs
  • anotherTableNames.cs
  • YETANOTHERTABLENAMEs.cs
  • Garbage_Tables.cs

我会喜欢有某种包装:


  • CleanTableName => TableName

  • CleanAnotherTableName => anotherTableName

  • CleanYetAnotherTableName => YETANOTHERTABLENAME

  • CleanGarbageTable => Garbage_Table

  • CleanTableName => TableName
  • CleanAnotherTableName => anotherTableName
  • CleanYetAnotherTableName => YETANOTHERTABLENAME
  • CleanGarbageTable => Garbage_Table

一个方法是创建包装类?任何想法?

One approach would be to just create wrapper classes?.. Any ideas?

推荐答案

如果你去你的edmx文件您可以单击每个实体并在其中重命名(属性窗口中的实体集名称和名称)。然后,如果您重新生成由T4模板创建的课程,您的课程将会有新名称。

If you go to your edmx file you can click on each of the entities and rename them in there (Entity Set Name & Name in the properties window). Then if your regenerate the classes created by the T4 template your classes will have the new names.

这篇关于重命名实体框架T4模板生成的类名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆