msawczyn / EFDesigner2022

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
MIT License
123 stars 21 forks source link

"End1/2 Foreign Key Property" property for associations #16

Closed buchatsky closed 2 years ago

buchatsky commented 2 years ago

Proposed behaviour "End1/2 Foreign Key Property" property in "End1/2" category for association ends which have multiplicity 1 or 0..1, with combo suggesting the list of fields of respective entity (can be filtered by type of the referenced entity PK field). It should generate .HasForeignKey(t => t.\<FK Property>) clause for Reference Builder. Also user should be able to type the name of the property that does not exist on respective entity, in which case this name should be used as the name for the shadow property (instead of auto generated) and produce .HasForeignKey("<FK Property>") clause.

User scenarios:

Current behaviour Implicit (shadow) FK field with auto generated name is created hiddenly.

Versions EF Visual Editor: 4.1.2.0 Visual Studio 2022: 17.1.3

buchatsky commented 2 years ago

And the connected issue: auto generated name of the shadow property, produced by EF Designer, is always \<navigation property name>\<principal key property name>. E.g. if PK field name="CategoryId" instead of simple "Id", the shadow FK field name will be "CategoryCategoryId". EF itself checks if PK field name already contains the name of the Navigation property, and if so, does not prepend it. E.g. if there is no .HasForeignKey() clause at all, the produced FK field name is "CategoryId". EF Core ref

buchatsky commented 2 years ago

I'm sorry, I didn't notice that it was already implemented with Diagram->Allow Modeled Foreign Keys and Association->Foreign Key Property. So the basic issue can be closed. (But the comment regarding the auto generated name of the shadow DB field is still valid)