简体   繁体   English

如何解决类的名称不能自动单数化

[英]How fix the name for class not auto singularize

Using EF to create the classes I choose the singularize option. 使用EF创建类,我选择单数化选项。 Some of the classes were singularize but other doesn't. 一些类是单数的,而其他则不是。

This work ok: 这项工作还可以:

products -> product
presentations -> presentation

But this two wasn't: 但是这两个不是:

price_sources -x-> price_source
user_types -x-> user_type

在这里输入代码

  • How can I fix the names of the classes weren't singularized? 我该如何解决未单数化的类的名称?
  • How can I fix the names of the classes with underscore? 如何用下划线固定类的名称?
  • How make sure next update from db does not break the names again? 如何确保db的下一次更新不会再次破坏名称?

Manual method: 手动方式:

Right click on empty space in the edmx window and select Model Browser . 右键单击edmx窗口中的空白区域,然后选择“ Model Browser

In the Model Browser of the edmx file you can rename the generated class names for the Tables under the DBModel --> Entity Types by right clicking on the class names and selecting Rename . 在edmx文件的Model Browser中,可以通过右键单击类名称并选择“ RenameRename DBModel --> Entity Types下表的生成类名称。 This will not break the code on subsequent updating of the models from database. 在随后从数据库更新模型时,这不会破坏代码。 But if you delete and re-add the same table you will have to repeat the above steps. 但是,如果删除并重新添加同一张表,则必须重复上述步骤。

I do these steps to avoid the CA warning for using underscores in class / property names 我执行这些步骤以避免在类/属性名称中使用下划线的CA警告

The answer is that tables with underscores cannot be automatically pluaralized/singularized in EM. 答案是带有下划线的表不能在EM中自动复数/单数化。

For more details, see: https://blogs.msdn.microsoft.com/efdesign/2008/12/01/pluralization/ 有关更多详细信息,请参阅: https : //blogs.msdn.microsoft.com/efdesign/2008/12/01/pluralization/

You will have to configure the table name explicitly. 您将必须显式配置表名称。

You can also use a custom pluralization service to write your own rules. 您还可以使用自定义的多元化服务编写自己的规则。

Details here: Entity Framework EDMX - Entity Pluralization Fix 此处的详细信息: 实体框架EDMX-实体复数修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM