4

We have found some bugs for certain words with the PluralizationService, for example it thinks "Campus" is plural, and it singularizes it by "Campu".

Anyhow, we have figured out how to add custom mappings to the service using the ICustomPluralizationMapping interface, the problem is, how do we tell the EntityModelCodeGenerator to use our custom service instead of the base one?

We are using EF 4.2 database first with custom T4 templates.

EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62
  • 1
    Actually, you are using database first. Otherwise you'd be asking how to get EF to pluralize the entity "Campus" into the table "Campuses" (model first). Also, if your table names are already singular, why not just disable the pluralization/singularization altogether? – Danny Varod Jun 18 '12 at 22:59
  • possible duplicate of [Is there a way to set custom pluralizations in EDM designer 2010?](http://stackoverflow.com/questions/2696825/is-there-a-way-to-set-custom-pluralizations-in-edm-designer-2010) – Ladislav Mrnka Jun 19 '12 at 08:14
  • Danny, yes you are correct, it's actually database first. If we disable pluralization, then we don't get the pluralized version of Entities in our object context. – EkoostikMartin Jun 19 '12 at 13:50
  • Ladislav, it is a duplicate by strict definition, but the accepted answer in that question is not helpful. The linked example is arbitrary, and I can't figure out where to put the custom EntityModelSchemaGenerator code for my scenario. – EkoostikMartin Jun 19 '12 at 13:52

1 Answers1

1

Maybe this article is helpful: http://blogs.msdn.com/b/efdesign/archive/2008/12/02/pluralization.aspx

Update1: You would need to add this code (sample):

//Create an EDM from SSDL generator
EntityModelSchemaGenerator generator =
    new EntityModelSchemaGenerator(
        storageModel,  
        "MyNamespace",
        "MyContainer", 
        pluralizationService);

//Generate CSDL and MSL (in memory)
generator.GenerateMetadata();

to the T4 template. In order to do that, you have to add the template to your project: Right click on a free space in the model designer and chose "Add code generation item". Then select the desired template and you will be able to customize this template.

Ref: http://onlinecoder.blogspot.de/2011/03/customize-entity-framework-code.html and http://www.matthidinger.com/archive/2010/02/09/customizing-the-entity-framework-t4-template-suppressing-code-analysis.aspx

Update2: Text Transformations & Finding Entity Plural (Collection)

Community
  • 1
  • 1
SolarX
  • 1,873
  • 2
  • 18
  • 26
  • Yes, I've seen this article, it is helpful, but the question is, where do I place the call to EntityModelSchemaGenerator? – EkoostikMartin Jun 19 '12 at 19:17
  • but this won't change the entity names we see in entity designer, am I right? Afaik, in db-first, T4 templates are used to generate the final POCO classes. – Ivan Ferrer Villa Sep 16 '15 at 19:33