Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How DbSet names can be customized? #209

Open
IvanFarkas opened this issue May 3, 2022 · 1 comment
Open

How DbSet names can be customized? #209

IvanFarkas opened this issue May 3, 2022 · 1 comment
Labels
question Further information is requested

Comments

@IvanFarkas
Copy link

How DbSet names can be customized?

I find this tool amazing and invaluable. Thank you very much Tony for your contribution.

I've seen the previous similar questions, but the answer is wage or perhaps I missed something.

I customized Entities massively using the EntityTypeGenerator and ScaffoldingDesignTimeServices.
I even added a data dictionary to translate meaningless and totally unnecessary abbreviations (num -> Number, amt -> Amount, ind -> Indicator, etc.) in table names and columns to a modern naming convention that could be a good base for domain driven design.

services.AddHandlebarsTransformers(
  e => Util.UpdateName("Table", e),
  e => Util.UpdateName("Table", e),
  e => new EntityPropertyInfo(Util.UpdateName("Column", e.PropertyType), Util.UpdateName("Column", e.PropertyName), e.PropertyIsNullable),
  e => new EntityPropertyInfo(Util.UpdateName("Column", e.PropertyType), Util.UpdateName("Column", e.PropertyName), e.PropertyIsNullable),
  e => new EntityPropertyInfo(Util.UpdateName("Column", e.PropertyType), Util.UpdateName("Column", e.PropertyName), e.PropertyIsNullable));

I tried to use DbContextGenerator like EntityTypeGenerator, but I could not accomplish it easily.
The only alternative I found is to replicate the HbsCSharpDbContextGenerator class and use my version of the GenerateClass() method to set the set-property-name dbSets Dictionary item used in DbSets.hbs

Any help, pointer is greatly appreciated.
Again, thx Tony for this marvelous tool!

@IvanFarkas IvanFarkas added the question Further information is requested label May 3, 2022
@tonysneed
Copy link
Contributor

Hi @IvanFarkas,

I think you're on the right track. You'll want to follow guidelines for Taking Full Control by Extending Handlebars Generators. Create a class that inherits from HbsCSharpDbContextGenerator, then override the GenerateClass method. You can see an example of this pattern with the HbsCSharpEntityTypeGenerator in the ef-core-community-handlebars repo.

Thanks also for the kudos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants