EntityTypeBuilder: .IsRequired() is ignored if used after .OnDelete() #23555
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
regression
Servicing-approved
type-bug
Milestone
Problem
When configuring a non-nullable foreign key with FluentAPI,
.isRequired()
is ignored when called after.OnDelete()
.Code
There are 2 models, connected by a 1-to-many relationship:
I'd like every city to belong to some country. This means, make the foreign key
City.CountryId
non-nullable.Now, this doesn't work:
But this does:
The only difference is the order of
IsRequired()
andOnDelete()
.The first (buggy) snippet generates a database migration with a nullable foreign key:
And the second doesn't:
Diagnostics
EF Core version: 5.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 3.1
Operating system: MacOS (reproducible on Windows too)
IDE: command line
The text was updated successfully, but these errors were encountered: