问题
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.
回答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)
来源:https://stackoverflow.com/questions/11090639/entity-framework-edmx-entity-pluralization-fix