Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Scaffolding: Fix missing HasForeignKey when principal key is an alternate key #29731

Merged
merged 1 commit into from
Jan 4, 2023

Conversation

bricelam
Copy link
Contributor

@bricelam bricelam commented Dec 1, 2022

When scaffolding an EF model from a database schema and using data annotations, incomplete code is generated for foreign key constraints referencing non-primary keys. This fix enables the missing code to be scaffolded.

Fixes #29418

Customer impact

Multiple customers have reported this. The only workaround is to update the scaffolded code once you discover it's incomplete.

The only indication that the code is incomplete is a runtime exception that will occur when querying data using the foreign key:

SqlException: Invalid column name '{wrong-foreign-key-column}'.

Regression

Yes. EF Core 6 generated the correct code.

Testing

Added automated scaffolding tests covering several scenarios involving alternate principal keys.

Risk

Low. This just causes the same code to be generated whether or not you're using data annotations.

…nate key

Also adds coverage for more scenarios involving alternate principal keys

Fixes dotnet#29418
@AndriySvyryd
Copy link
Member

Don't forget the patch template

@bricelam

This comment was marked as off-topic.

@bricelam

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants