Why does entity framework pluralize and capitalize entity class names?

丶灬走出姿态 提交于 2019-12-11 14:22:08

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3444013/why-does-entity-framework-pluralize-and-capitalize-entity-class-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!