为什么实体框架要使用复数和大写的实体类名称?

发布于 2024-09-13 12:45:15 字数 64 浏览 4 评论 0原文

为什么实体框架默认将所有类名复数并首字母大写?这样做有什么好处呢?可能是一个愚蠢的问题......但只是出于好奇?

Why does entity framework pluralize all the class names and capitalize the first letters by default? What are the advantages of doing this ? Probably a stupid question...but just out of curiosity?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

非要怀念 2024-09-20 12:45:15

.NET 风格指南规定所有类名都应采用 CamelCase。

我不知道复数,它不是复数单个实体对象,是吗?不过对于收藏来说还是有意义的。

The .NET style guidelines say that all class names should be in CamelCase.

I don't know about pluralizing though, it's not pluralizing individual entity objects, is it? Would make sense for collections, though.

蔚蓝源自深海 2024-09-20 12:45:15

.NET 开发类库设计指南,它规定所有类名都应采用 Pascal 大小写,它定义为:

“标识符中的第一个字母
以及每个的第一个字母
随后的连接词是
大写。您可以使用帕斯卡案例
对于三个或更多的标识符
人物。例如:

背景颜色”

至于复数,我发现当您使用实体框架模型设计器的默认设置时,您会得到相反的结果。它将把复数表名称转换为其单数等效项。例如,使用 Northwind 数据库并使用默认设置我发现设计者会将 Products 表更改为名为 Product 的类,将类别表更改为名为 Category 的类,这是有道理的,因为对象的单个实例将。是 Product 而不是 Products

如果您得到相反的效果,那么我很困惑,请查看这篇文章 - 实体框架 4.0:复数化 作者:Dan Rigsby,这也许解释发生了什么。

In the Capitalization Conventions section of the .NET Design Guidelines for Developing Class Libraries, it states that all class names should be in Pascal case, which it defines as:

"The first letter in the identifier
and the first letter of each
subsequent concatenated word are
capitalized. You can use Pascal case
for identifiers of three or more
characters. For example:

BackColor"

As for pluralization, I find you get the opposite when you use the default settings for the Entity Framework model designer. It will convert plural Table names to their singular equivalent. For instance, using the Northwind database and using the default settings I find that the designer will change the Products table to a class called Product and Categories table to a class called Category. This makes sense since a single instance of an object would be a Product and not a Products.

If you are getting the opposite effect then I'm puzzled. However, check out this article - Entity Framework 4.0: Pluralization by Dan Rigsby, which perhaps explains what is happening.

微凉徒眸意 2024-09-20 12:45:15

您应该将类​​单数化,将集合复数化。例如,单数和复数是通过 ef

var customer = new Customer{}; 完成的。 //单一类
db.Customers.AddObject(客户); ObjectSEt 是复数的

customer.Orders.Add(new Order{});订单导航属性是复数的。

要了解更多信息,您还可以阅读我书中的 7-6 个食谱。

You should singularize a class and pluralize a collection. For example this is where singularazliation and pluralization is done by ef

var customer = new Customer{}; //singular class
db.Customers.AddObject(customer); ObjectSEt is pluralized

customer.Orders.Add(new Order{}); Orders navigation property is pluralized.

To learn more u can also read 7-6 recipe in my book.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文