实体框架代码优先命名约定 - 回复数表名? [英] Entity Framework Code First naming conventions - back to plural table names?

查看:91
本文介绍了实体框架代码优先命名约定 - 回复数表名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是采取了裂纹在实体框架代码第一位。继他们的命名规则,我们现在必须命名为表复数不要有工具进行干预。我知道的映射可以超过缠身。我的问题是,经过多年继奇异的命名规则是,我们回到使用多个名字?

I am just taking a crack at entity framework code first. Following their naming convention, we now have to name our tables plural to not have to intervene with the tool. I know the mappings can be over ridden. My question is, after years of following the singular naming convention are we back to using plural names?

另外,我想知道为什么新的例子是使用罗斯文,而不是冒险作品。我想原因是因为AW采用单数命名,他们将不能够炫耀的无码功能

Also, I was wondering why the new examples were using Northwind instead of Adventure Works. I'm thinking the reason is because AW uses singular naming and they wouldn't be able to show off the no code features

推荐答案

代码首先RTM版本将全面支持名为 可插拔约定一个很酷的功能在这里你可以如你提到的添加或更换默认的约定。

The RTM version of Code First will fully support a cool feature called Pluggable Conventions where you can add or replace the default conventions such as the one you mentioned.

幸运的是,你在找什么已经包含在CTP5。您可以删除的 PluralizingTableNameConvention 的约定关掉复数表名约定。这是所有你需要写这件事的代码:

Fortunately, what you are looking for is already included in CTP5. You can switch off the pluralizing table names convention with removing PluralizingTableNameConvention convention. This is all the code you need to write for this matter:

using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{    
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}



结果
关于您的问题谢胜利,原因你更多看到Northwind数据库比探险工程正因为AW是一个庞大而罗斯文因此是一个相当小的数据库,使之更适合样品和演练。这就是说,你仍然需要编写一些代码,在代码优先Northwind数据库工作。


About your secound questions, the reason you more see Northwind database than Adventure Works is just because AW is a huge and Northwind is a fairly small database hence make it a better fit for samples and Walkthroughs. That said, you still need to write some code to work with Northwind database in Code First.

这篇关于实体框架代码优先命名约定 - 回复数表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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