TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

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

[Proposal] Add more information about field/entity to propertyTransformer/EntityPropertyInfo #84

Closed MyEidos closed 5 years ago

MyEidos commented 5 years ago

It is hard and sometimes not flexible to use propertyTransformer because of luck of information inside method. It will be great to have next information in propertyTransformer:

  1. Information about current table: name, metadata etc.
  2. Information about property in EntityPropertyInfo: metadata etc.
tonysneed commented 5 years ago

The transformer methods are, as you point out, limited in terms of what metadata is communicated to the Handlebars template, namely, property name and type. The reason for this is simplicity and performance.

For scenarios where you need to take more control of the transformation process, it is recommended you create a class that extends HbsCSharpEntityTypeGenerator and override GenerateProperties. Then register your MyCSharpEntityTypeGenerator in your ScaffoldingDesignTimeServices class. See #61 for detailed instructions.

tonysneed commented 5 years ago

@MyEidos Have you tried the approach I suggested with extending HbsCSharpEntityTypeGenerator? Does it allow you to achieve what you'd like to accomplish?

tonysneed commented 5 years ago

Closing this as resolved. @MyEidos Please let me know if this is not the case.

aeslinger0 commented 4 years ago

@tonysneed, could this be looked at again? Your proposal to extend HbsCSharpEntityTypeGenerator doesn't work well because the base implementation of GenerateNavigationProperties, for example, includes references to private members in the base class. Could you either make those references protected or, even more ideally, pass in the objects such as the INavigation instance into the navPropertyTransformer?

Another idea (not mutally exclusive from the other ideas) would be to add calls to partial methods inside the methods that generate properties, nav properties, etc, so a sub class could extend the logic without having to recreate the existing logic - which would incur a risk of getting outdated if the original logic in the base class changes.