Search code examples
c#entity-frameworkef-database-firstpluralize

Entity Framework 6, Database-First & Custom Pluralization


To the point; is there any way to customize the pluralization service for database-first EF models?

Specifically, I'd like to use the *Set suffix notation, wherein the entity sets and collection navigation properties are named accordingly:

  • User to UserSet
  • Report to ReportSet
  • etc.

I know I've seen this made possible with code-first, however I'm stuck with database-first as the development process.

I'm aware of IPluralizationService, but can't figure out how to substitute my custom implementation.

Currently, I'm manually working through the entity sets and collection properties in the model browser (VS2015) and appending "Set" to each of them; this is fine to do once, however whenever I regenerate the model it becomes quite the pain in my ass.

Any suggestions?


Solution

  • I ended up writing a script (PHP of all things) to perform XML transformations on the EDMX file. I lose support for some of the more obscure features due to the way the transformation is performed, however it was the only way I could do it without sacrificing kittens to an omniscient force. Most importantly, it maintains the mappings as expected.

    I couldn't figure out a way to work the transformation script into the generation pipeline yet; though I may look at invoking it from the text template.