Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework EDMX - Entity Pluralization Fix

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.

like image 987
EkoostikMartin Avatar asked Jan 19 '26 04:01

EkoostikMartin


1 Answers

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)

like image 191
SolarX Avatar answered Jan 20 '26 21:01

SolarX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!