简体   繁体   English

EF6 db首先对包含下划线的表名进行复数/单数化

[英]EF6 db first pluralize/singularize for table names that contain underscores

I am trying to create a new Entity Data Model (database first) with entity framework 6 using the wizard provided in Visual Studio 2015 Community edition. 我正在尝试使用Visual Studio 2015社区版中提供的向导使用实体框架6创建新的实体数据模型(首先是数据库)。 All my table names are pluralized (ex. mn_Bills). 我所有的表名都是复数的(例如mn_Bills)。 I chose the "Pluralize or singularize generated object names" but this does not singularizes the object names (ie the generated class for table mn_Bills is mn_Bills in a mn_Bills.cs file). 我选择了“对生成的对象名称进行复数或单数化”,但这不会对对象名称进行单数化(即,表mn_Bills的生成类是mn_Bills.cs文件中的mn_Bills)。

I have modified the "Name" and "Entity Set Name" in the Model Browser which resolved only partly the problem. 我已经在模型浏览器中修改了“名称”和“实体集名称”,这只能部分解决问题。 The classes generated are singular, which is good, but the foreign key associations for N to 1 associations are pluralized: 生成的类是单数,这很好,但是N对1关联的外键关联是复数的:

public partial class mn_Bill
{
    ...
    public virtual mn_Clearing mn_Clearings { get; set; }
}

Do you know if there is any workaround for this problem (besides changing the table names)? 您是否知道是否有解决此问题的方法(更改表名之外)?

I met a similar problem with underscore table names and it seems that the PluralizationService doesn't support underscores. 我在下划线表名上遇到了类似的问题,而且PluralizationService似乎不支持下划线。

The answer, it seems, is to override the default service with some of your own code. 答案似乎是用您自己的一些代码覆盖默认服务。

I've not done this for a database first edmx solution, because I'm using an alternative code generation engine - but this may be possible to override in the code generation step. 我没有针对数据库的第一个edmx解决方案执行此操作,因为我使用的是备用代码生成引擎-但这可以在代码生成步骤中覆盖。

See this answer here: 在这里查看此答案:

Entity Framework EDMX - Entity Pluralization Fix 实体框架EDMX-实体复数修复

https://blogs.msdn.microsoft.com/efdesign/2008/12/01/pluralization/ https://blogs.msdn.microsoft.com/efdesign/2008/12/01/pluralization/

Just select "Pluralize or singularize" option in the EDMX wizard. 只需在EDMX向导中选择“复数化或单数化”选项。

在此处输入图片说明

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

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