-
-
Notifications
You must be signed in to change notification settings - Fork 301
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
Missing HasForeignKey when referencing a navigation property with a unique constraint. (EF Core 7 preview) #1554
Comments
What happens when you do not use t4? I need a full SQL schema to investigate |
@ErikEJ It is not related to T4 template usage. |
Yes, I am able to repro - and EF Core 6 reverse engineering generates this with DataAnnotations enabled: entity.HasOne(d => d.ColorCodeNavigation)
.WithMany(p => p.Car)
.HasPrincipalKey(p => p.ColorCode)
.HasForeignKey(d => d.ColorCode)
.HasConstraintName("FK_Car_Color"); |
I have filed a bug in the EF Core repo: dotnet/efcore#29418 |
Confirmed fixed in 7.0.3 |
@TimKras Thanks for the update, EF Core Power Tools uses 7.0.3 now |
Describe what is not working as expected.
Provide steps to reproduce
The tool is generating this code:
At runtime I get this exception:
Indeed, the column does not exists in the database.
When adding manual this line, everything is working like it should:
--> it looks like the HasForeignKey() is missing.
Provide technical details
EF Core version in use: EF Core 7
Is Handlebars used: no
Is T4 used: no
Is .dacpac used: no
EF Core Power Tools version: latest version
Database engine: SQL Server
Visual Studio version: Visual Studio 2022
The text was updated successfully, but these errors were encountered: