Raheel Khan
Raheel Khan

Reputation: 14787

Using Code First and pluralizing ONLY `DbSet<Entity> Entities` entries

I want to disable pluralization for database tables which is easy enough. However, I use reflection and T4 templates to generate my context class.

public DbSet<User> User { get; set; }
public DbSet<Department> Department { get; set; }

Is there any way to use EF's to return pluralized names from within T4 templates so I can generate the following:

public DbSet<User> Users { get; set; }
public DbSet<Department> Departments { get; set; }

Some function like string name = EF.GetPluralizedName("User");, etc.

I am using VS2010 targeting .NET 4 in case that helps.

Upvotes: 1

Views: 435

Answers (1)

COLD TOLD
COLD TOLD

Reputation: 13599

you can use pluralization service it would be something like

string name = System.Data.Entity.Design.PluralizationServices.PluralizationService.
CreateService(System.Globalization.CultureInfo.CurrentUICulture).Pluralize("User");

Upvotes: 2

Related Questions