Search code examples
c#.netentity-framework-5pluralize

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.


Solution

  • 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");