CatFactory.EntityFrameworkCore icon indicating copy to clipboard operation
CatFactory.EntityFrameworkCore copied to clipboard

Customize naming conventions

Open glacasa opened this issue 5 years ago • 2 comments

My current codebase use specific naming conventions, and the generated code can't match them because some of these rules are hardcoded in the EntityFrameworkCoreProjectExtensions class.

If we replaced those extensions methods by a service class (like the INamingService), it would be easier to override the naming rules.

I can start working on this if you're ok, I just wanted to know your thoughts about this.

glacasa avatar Jul 08 '20 14:07 glacasa

This can be fixed by adding string value as property in settings, so this line:

=> string.Format("{0}Result", project.CodeNamingConvention.GetClassName(dbObject.Name));

Would be:

=> string.Format(EntityResultClassName, project.CodeNamingConvention.GetClassName(dbObject.Name));

The property can be defined like this:

public string EntityResultClassName { get; set; }

Also, if you want to change the code naming conventions for classes, properties, methods, etc You must create a class that implements ICodeNamingConvention interface and replace the instance in Project instance.

Let me know if this is useful.

hherzl avatar Jul 09 '20 06:07 hherzl

I don't think this will work for me. My DB table names are pluralized, but the code assume they are singular.

For the EntityName, I want to use NamingService.Singularize on the class name. If I do this in the CodeNamingConvention, it will have side-effect on all other methods using CodeNamingConvention.GetClassName

glacasa avatar Jul 09 '20 07:07 glacasa