Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First naming conventions - back to plural table names?

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?

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

like image 251
Paul Speranza Avatar asked Dec 13 '10 00:12

Paul Speranza


1 Answers

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.

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>(); } 


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.

like image 187
Morteza Manavi Avatar answered Sep 18 '22 06:09

Morteza Manavi