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

Unable to expose Foreign Key property for associations #55

Closed
TondaKrist opened this issue Feb 13, 2019 · 6 comments
Closed

Unable to expose Foreign Key property for associations #55

TondaKrist opened this issue Feb 13, 2019 · 6 comments
Labels
as designed As designed enhancement New feature request released Issue is resolved in a current release
Milestone

Comments

@TondaKrist
Copy link

Foreign Key properties are not generated in code.

@msawczyn
Copy link
Owner

No, they're not; that's as-designed.

The tool is centered around object modeling, not data modeling. Foreign keys are database concepts rather than object concepts. To access associated objects you access the objects ... the foreign keys are used for persistence only, and violate the concept of "plain old C# objects" since they wouldn't be there if you weren't in a persistence context.

EF will use those to support whatever it needs to do its job, and the code generated for the DbContext does indeed specify the keys (since that's where they're important). But not in the entities.

@msawczyn msawczyn added the as designed As designed label Feb 19, 2019
@TondaKrist
Copy link
Author

I understand that they are not auto generated, but it is a pitty that I can not even add them manually in partial class using EF naming convention. For some performance issues we use really often FK to attaching objects. EF designer is really nice tool, and I am personally so sad we can not use it for both object and data modeling.

@msawczyn msawczyn added the enhancement New feature request label Feb 21, 2019
@msawczyn
Copy link
Owner

I've tagged this as an enhancement request. It's possible that we can set a flag at the designer (and class level, for override) to generate those, but I'll need to look into the implications.

@Cyclonit
Copy link

I'd like to add my +1 to this issue. this enhancement would allow using EFDesigner for very resource hungry use cases.

@msawczyn msawczyn added this to the 1.4.0.0 milestone Dec 23, 2019
@msawczyn msawczyn modified the milestones: 1.4.0.0, 2.0.0.0 Jan 1, 2020
@msawczyn msawczyn added the pending release Issue is resolved in the current codebase, will be published with the next release label Feb 17, 2020
@msawczyn msawczyn modified the milestones: 2.0.0.0, 2.0.0 Mar 27, 2020
@msawczyn msawczyn added 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 Apr 11, 2020
@SimonNeP
Copy link

SimonNeP commented Feb 3, 2021

Hello, I stumbled across this issue but cannot find the option to generate the foreign key for the association inside my class.
The properties on class level:
image
My designer:
image

Maybe I'm just looking at the wrong place?

@msawczyn
Copy link
Owner

@SimonNeP -

This functionality has been there for a while, but the documentation certainly needs updated; just trying to find the time

At the model level, selecting the design surface, set Allow Modeled Foreign Keys to True. Now you can select an association and you'll see a property named Foreign Key Property where you can type in the name of the foreign key property. The designer will place it in the correct class. In the case of more than one identity property on the dependent class, you'll likely want to name all of the FK properties, comma-separated. The property will be added to the dependent class in the designer with a different glyph.

Note that this can't be done on a many-to-many association, since those are persisted via a join table.

If you want the names of the FK properties to show up on the diagram attached to the association, set the designer's Show Foreign Key Property Names value to True.

Hope this helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
as designed As designed enhancement New feature request released Issue is resolved in a current release
Projects
None yet
Development

No branches or pull requests

4 participants