9

As my database was designed using german table- and column names, the default pluralisation feature of entity framework doesn't work for me.

I have found a couple of resources where this is discussed, but none of them seem to work.

What i have found: There is the PluralisationService where i can add the mappings:

PluralizationService pluralizer =
      PluralizationService.CreateService(CultureInfo.GetCultureInfo("en-us"));
ICustomPluralizationMapping mapping = ps as ICustomPluralizationMapping;
mapping.AddWord("Tabelle", "Tabellen");

But what's next? I have tried to:

EntityModelSchemaGenerator generator = new EntityModelSchemaGenerator(container);
generator.PluralizationService = pluralizer;
generator.GenerateMetadata();

and put both of them in my POCO T4 Template. But it throwed the following exception:

The EntityContainer 'ContainerName' is not a store EntityContainer. Parameter name: storeEntityContainer
at System.Data.Entity.Design.EntityModelSchemaGenerator.Initialize(...)
at Microsoft.VisualStudio.TextTemplating...GeneratedTextTransformation.TransformText()
Cœur
  • 37,241
  • 25
  • 195
  • 267
Gerwald
  • 1,549
  • 2
  • 18
  • 42
  • +1 for the investigation in the question. This is how questions should be asked. Struggled with this issue myself without much success. – Judo Jul 23 '12 at 14:17

3 Answers3

0

I'm also looking for the same thing. Maybe this can help. I'm just not willing to pay for such a basic feature.

EDIT:

The code you posted is to be used with EdmGen2 wich will give you CSDL, SSDL or MSL files pluralized according to your class.

Androiderson
  • 16,865
  • 6
  • 62
  • 72
0

To completely customize the table names in EF Code First, you can use the Table attribute to explicitly specify the name of the table associated with a class:

[Table("InternalBlogs")]
public class Blog
{
    //...
}
Sidharth Mudgal
  • 4,234
  • 19
  • 25
0

A very old question, but if someone is still looking for a possible workflow/solution:

I had a similar problem where I wanted to customize the schema import (CSDL) from the database. The solution / workflow was as follows:

  1. Deployed the database schema (I used Visual Studio Database Project VS 201x) to a local database
  2. Imported the database model using EDMGEN to create the CSDL, SSDL and MSDL files http://msdn.microsoft.com/en-us/library/vstudio/bb387165(v=vs.110).aspx
  3. Modified EDMGEN2 with my changes on how to handle pluralization and naming with custom rules and created EDMX file
  4. Ran the T4 templates (with additional customization as needed) to create output.
Haroon
  • 1,052
  • 13
  • 28