如何为Entity Framework 5定制多元化

Ger*_*ald 9 entity-framework poco pluralize entity-framework-4 entity-framework-5

由于我的数据库是使用德语表和列名设计的,因此实体框架的默认复数功能对我不起作用.

我已经找到了几个讨论这个问题的资源,但它们似乎都没有用.

我发现:有PluralisationService,我可以添加映射:

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

但下一步是什么?我试过:

EntityModelSchemaGenerator generator = new EntityModelSchemaGenerator(container);
generator.PluralizationService = pluralizer;
generator.GenerateMetadata();
Run Code Online (Sandbox Code Playgroud)

并将它们都放在我的POCO T4模板中.但它引发了以下异常:

EntityContainer'ContainerName'不是商店EntityContainer.参数名称:StoreEntityContainer
at System.Data.Entity.Design.EntityModelSchemaGenerator.Initialize(...)
at Microsoft.VisualStudio.TextTemplating ... GeneratedTextTransformation.TransformText()

And*_*son 0

我也在寻找同样的东西。也许会有所帮助。我只是不愿意为这样的基本功能付费。

编辑:

您发布的代码将与EdmGen2一起使用,它将根据您的班级为您提供复数的 CSDL、SSDL 或 MSL 文件。