Missing HasForeignKey when referencing a navigation property with a unique constraint. (EF Core 7 preview)
See original GitHub issueDescribe what is not working as expected.
Provide steps to reproduce
The tool is generating this code:
entity.HasOne(d => d.VrijstellingsCodeBHNavigation).WithMany(p => p.Klant)
.HasPrincipalKey(p => p.VrijstellingsCodeBH)
.HasConstraintName("FK_Klant_BTWVrijstellingsCode");
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:
entity.HasOne(d => d.VrijstellingsCodeBHNavigation).WithMany(p => p.Klant)
.HasForeignKey(p => p.VrijstellingsCodeBH)
.HasPrincipalKey(p => p.VrijstellingsCodeBH)
.HasConstraintName("FK_Klant_BTWVrijstellingsCode");
–> 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
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
EF Core 7 Rev eng: Missing HasForeignKey when ...
EF Core 7 Rev eng: Missing HasForeignKey when referencing a navigation property with a unique constraint with DataAnnotations on #29418.
Read more >EF Core: Navigational properties to views
I try to get navigational properties to work between a object that I own and maintain and a view that is controlled by...
Read more >Breaking changes in EF Core 7.0 (EF7)
Complete list of breaking changes introduced in Entity Framework Core 7.0 (EF7)
Read more >Entity Framework Core: Foreign key linked with a non-primary ...
The unique constraint means that values cannot be repeated in different entries in a column. Once we configure a field as PrincipalKey, the ......
Read more >Entity Framework Core Migrations
The migrations feature in Entity Framework Core enables you to make changes to your model and then propagate those changes to your database ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirmed fixed in 7.0.3
I have filed a bug in the EF Core repo: https://github.com/dotnet/efcore/issues/29418