Entity Framework EDMX - Entity Pluralization Fix

笑着哭i 提交于 2019-12-02 06:30:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!