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?
相关问题
- How to Specify a Compound key in Entity Framework
- ToList method not available for TrackableCollectio
- Getting “Cannot insert the value NULL into column”
- How can I implement Query Interception in a LINQ t
- Setting table level WillCascadeOnDelete not availa
相关文章
- How do we alias a Sql Server instance name used in
- entity type has no key defined - Code first
- POCO Vs Entity Framework Generated Classes? [close
- The 'DbProviderFactories' section can only
- Is SaveChanges() Necessary with Function Imports (
- Entity Framework - An item with the same key has a
- Setup EF4 data source for SQL Compact 4
- Id of newly added Entity before SaveChanges()
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:
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 calledCategory
. This makes sense since a single instance of an object would be aProduct
and not aProducts
.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.
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.
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.