TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

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

Enhancements For Navigation Properties #160

Closed john-larson closed 3 years ago

john-larson commented 3 years ago

Right now, when trying to filter navigation properties for transformation, we only have access to certain properties such as name, type and nullability.

I propose introducing a "NavigationPropertyInfo" class that derives from "EntityPropertyInfo". It will contain an "INavigation Navigation" property so that users of the library will not be limited to certain properties of the original EF Core navigation. This will increase the extensibility of the project. It will also benefit the templating since users will have access to all properties of the navigation object.

I've already done some work in that regard. I am planning to open a PR for this issue.

tonysneed commented 3 years ago

Good proposal. I will have a look this week.

john-larson commented 3 years ago

Hi @tonysneed. Did you have a chance to look at the pull request?

tonysneed commented 3 years ago

Thanks for your PR. Looking at it right now.

skuami commented 3 years ago

This is my first comment on this project: Great job Tony! I am in the same situation that I need more information to transform my nav properties properly.

I am having following issue which lead me here. ;-)

It would be helpful to get the referenced table name and/or constraint name.

tonysneed commented 3 years ago

@john-larson Please see my comment in your PR.

tonysneed commented 3 years ago

@skuami Thanks for your inquiry. As soon as john-larson fixes some issues with his PR, I can merge it and you'll have the needed functionality.

skuami commented 3 years ago

@tonysneed & @john-larson is there a way to find out which navigation property is currently changed? By that I mean I have my services.AddHandlebrasTransformers(navPropertyTransformer: MyMethod);

This method gets called for all my nav properties. With the additional information from @john-larson PR I am able to change to name in a way I needed it to be. The probelm I am facing now is, that I rename also property names that should not be changed - specifically the .HasPrinicpalKey():

entity.HasOne(d => d.TranslationKey1) .WithMany(p => p.TranslationTranslationKey1s) .HasPrincipalKey(p => p.TitleTranslationKey) .HasForeignKey(d => d.TranslationKey) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_TranslationNewsTitle");

tonysneed commented 3 years ago

@skuami To get the best answer to your question, I would suggest separating it from the scaffolding tool and posting it to StackOverflow as a question on the EF Core API.

tonysneed commented 3 years ago

@john-larson Have you abandoned this PR? If so, please let me know so I can close it. Perhaps @skuami would be willing to pick it up?

john-larson commented 3 years ago

@tonysneed Sorry, I missed the conversation. I was too busy lately. I would be willing to look into the problems with the unit tests but I don't know when I can find the time for it.

tonysneed commented 3 years ago

Will re-open this issue if @john-larson, @skuami or someone else can fix issues and add tests to #161.