TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
210 stars 53 forks source link

[Feature] Add primary-key, primary-key-type, and property-primary-key expressions #173

Closed coldacid closed 3 years ago

coldacid commented 3 years ago

Is your feature request related to a problem? Please describe. There is currently no way to determine the primary key property or its type in an entity class. This causes me problems when using Entity Framework Power Tools to refresh a third party database in my solution, where I need the entity classes to inherit from a generic base class that takes the type of the primary key's property as the type parameter.

Describe the solution you'd like Add three new expressions:

Describe alternatives you've considered No other alternatives are possible without having to carefully go through all changes in the generated entity type files and adapting each one by hand to add the base type inheritance (which also requires adding override for the "Id"/primary key property on each class).

Additional context Add any other context or screenshots about the feature request here.

tonysneed commented 3 years ago

This is a situation where you will need to take full control of entity generation by extending HbsCSharpEntityTypeGenerator and overriding GenerateProperties. See here for an example of how to do that.