简体   繁体   English

首先使用实体​​框架模型的多个表名

[英]Plural table names with Entity Frameworks Model First

I'm giving EF Model first a go. 我先尝试一下EF模型。 I'm using EF 4.1 我正在使用EF 4.1

Pretty much followed this article 几乎跟着这篇文章

I've set PluraliseNewObjects to False on the Model and also in Options->Database Tools ->O/R Designer set Pluralization of names to false. 我已在模型上将PluraliseNewObjects设置为False,并且还在选项->数据库工具-> O / R设计器中将名称的复数设置为false。

Neither have any effect - when I generate a new schema from the model the table names are always pluralised - is it possible to disable this? 都没有任何作用-当我从模型中生成新模式时,表名始终是复数形式-可以禁用此功能吗?

OK - I've found one way to achieve what I want - but it's a pretty daft route. 好的-我找到了一种实现我想要的方法的方法-但这是一条很愚蠢的路线。

  1. Generated db with the plural names (interesting that it only pluralised the tables mapping to types - not the auto-generated linking tables for many to many joins). 生成的数据库具有复数名称(有趣的是,它仅将映射到类型的表复数-而不是用于多对多联接的自动生成的链接表)。

  2. Manually renamed the tables in the database 手动重命名数据库中的表

  3. Deleted Model from the project and recreated based on existing database schema (the one I've just renamed). 从项目中删除了Model,并根据现有的数据库模式(我刚刚重命名的模式)进行了重新创建。

  4. Model is now correctly mapped to singularly names tables. 现在,模型已正确映射到单数名称表。

I'll wait and see if anyone comes up with a more sensible way of achieving this.... 我将拭目以待,看看是否有人想出一种更明智的方法来实现这一目标。

The names of the tables in the generated DDL seem to match the "Entity Set Name" values (different than the "Entity Name"). 生成的DDL中的表名称似乎与“实体集名称”值匹配(不同于“实体名称”)。 If you singularize the Entity Set Names, the table names in the DDL are singularized as well. 如果将实体集名称单数化,则DDL中的表名也将单数化。

This will have the possibly undesired effect of singularizing the EntitySet property names in your code, though. 但是,这将可能使代码中的EntitySet属性名称单数化。 Instead of: 代替:

myDatabase
.Products
.Where...
.Select...

your code will look like: 您的代码如下所示:

myDatabase
.Product
.Where...
.Select...

may or may not be an issue 可能是或不是问题

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

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