Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Foreign Key Column Names #250

Closed
superman-ivan opened this issue Dec 18, 2020 · 2 comments
Closed

Foreign Key Column Names #250

superman-ivan opened this issue Dec 18, 2020 · 2 comments
Labels
bug Confirmed bug enhancement New feature request released Issue is resolved in a current release
Milestone

Comments

@superman-ivan
Copy link

superman-ivan commented Dec 18, 2020

Hello Michael,

Great tool! We've been using it a lot for quite a whlie now! My quesition is about foreign key db column names. In v3 it seems the EFVE generates them with no underscore, e.g. .HasForeignKey("CategoryId"), while in v2.x it was with underscore, e.g. .HasForeignKey("Category_Id"), which is a breaking change for us when migrting to v.3.
But since I don't see other people having the same issue, it must be some configuration option we're missing?

Thanks!
Ivan

@superman-ivan
Copy link
Author

After some digging I found what template modification I need to make to make the tool generate the ".HasForeignKey" calls consistent to the way it was before the template upgrade that came with v3.
Note the underscores in code snipped from EFModelGenerator.ttinclude:

     [SuppressMessage("ReSharper", "ConvertIfStatementToReturnStatement")]
     protected static string CreateShadowPropertyName(Association association, List<string> foreignKeyColumns, ModelAttribute identityAttribute)
     {
        string GetShadowPropertyName(string nameBase)
        {
           if (association.SourceRole == EndpointRole.Dependent)
              return $"{nameBase}_{identityAttribute.Name}";

           if (association is BidirectionalAssociation)
              return $"{nameBase}_{identityAttribute.Name}";

           return $"{nameBase}_{identityAttribute.Name}";
        }

Would you consider revisiting the new template implementation to be consistent with the one that came with versions prior to v3? We would highly appreciate that. Thanks!
Ivan

@msawczyn
Copy link
Owner

Hi Ivan,

Yes, that was an unintended change. It needs to be reverted. I think we'll go a step farther and make it a global setting, since different folks like different patterns. I'll add those both patterns. Thanks for pointing it out!

@msawczyn msawczyn added this to the 3.0.2 milestone Dec 19, 2020
@msawczyn msawczyn added bug Confirmed bug pending release Issue is resolved in the current codebase, will be published with the next release enhancement New feature request released Issue is resolved in a current release and removed pending release Issue is resolved in the current codebase, will be published with the next release labels Dec 19, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Confirmed bug enhancement New feature request released Issue is resolved in a current release
Projects
None yet
Development

No branches or pull requests

2 participants