Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Designer> Singularize DbSet properties in DataContext
 

Pages: 1
Designer
Singularize DbSet properties in DataContext
Page:1/1 

  Print all messages in this thread  
Poster Message
jordyvaneijk
User



Location:
Amsterdam, Netherlands
Joined on:
04-Jan-2019 09:59:31
Posted:
2 posts
# Posted on: 04-Jan-2019 10:43:35.  
Hi all,

I'm using LLBLGen Pro V5.5 and after generating my code i see that the names of my DbSet properties inside the DataContext are pluralized. Because the database i use is in Dutch the english pluralization is worthless. Is there a setting which i can edit that makes sure that the name of the DbSet is the same name as the Entity So for example.

Generated code is for EFCore 2.0

Entity Customer (in dutch Klant)
will become
Code:

DbSet<Customer> Customers {get; set;}
//In dutch
DbSet<Klant> Klants {get; set;} // This should be Klanten instead of Klants


the preferred solution i'm looking for is something like this:
Code:

DbSet<Customer> Customer {get; set;} //So singularized no S on the end
//In dutch
DbSet<Klant> Klant {get; set;}


I hope someone can tell me how to fix this.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37377 posts
# Posted on: 04-Jan-2019 11:07:48.  
You can disable the pluralization plugin. Go to (in the designer) Tools -> Bind Designer events to plugins, then select with 'Designer event' 'NameSingularToPluralConversion' and uncheck the 'IsEnabled' checkbox.

This also controls the pluralization of names on e.g. navigators etc. The downside of this is that the plugin is disabled for all the projects you load, so if you work on multiple projects this might be less ideal.

You can also adjust the pluralization plugin code, if you want to. The plugin sourcecode comes with the sourcecode archive available under My account -> v5.5 -> Extras section on the website. In the plugins folder, you'll find the Inflector.cs file which is the root of this plugin, it's a bunch of simple regexps which you can e.g. alter to make it work for Dutch (but as Dutch' pluralization rules aren't that simple, this likely is a daunting task).

A 3rd way to solve this is by using a custom Context template for code generation. after you've loaded your project in the designer, click the Template bindings viewer icon in the toolbar (tools -> template bindings viewer). Then double click the SD_EF_Core_Context binding. At the bottom of the template, you'll see:

Code:
        public DbSet<<%=entity.Name%>> <%=GeneratorUtils.PluralizeString(entity.Name)%> { get; set; }


Simply remove the call to GeneratorUtils.PluralizeString and you'll get singular names. It's best if you create a copy of the template and bind it to the same template ID (SD_EF_Core_Context) using a new templatebindings file https://www.llblgen.com/Documentation/5.5/Designer/How%20To/TemplatesAdd.htm and give it a higher precedence number than the vanilla one (so it's picked over the vanilla one, it then overrules the templateID binding set by our templatebinding files).


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
jordyvaneijk
User



Location:
Amsterdam, Netherlands
Joined on:
04-Jan-2019 09:59:31
Posted:
2 posts
# Posted on: 04-Jan-2019 15:10:54.  
Hi Frans,

Thank you so much for the quick response. It's to bad that you can't enable / disable plugins on project basis, especially when you develop for multiple clients with different needs. Is this something that will be possible in a future release? I don't want to mess with the templates.

I took a look at the sourcecode for the plugin and maybe i will try and add the dutch pluralization rules to my own plugin. It looks very easy!

Thank you so much!
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37377 posts
# Posted on: 07-Jan-2019 09:55:17.  
You can't switch / enable then on a per-project basis, but that's indeed something we should add. We'll look into adding that in a future version. The inflector's rules are evaluated from back to front, so a rule added last will overrule any rules defined before it. For Dutch a rule to pluralize to 'n' or 'en' (which is the majority of the names) then should be added to the bottom. Indeed, you can't keep it enabled for other projects if those use English, which is a limitation.

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.