For optional relationships (when Foreign Key can accept Null
), a new ClientSetNull
behavior has been introduced since EF Core 2.0 as the default option for delete behavior DeleteBehavior.ClientSetNull
.
This has SetNull
semantics for tracked entities and Restrict
(no action) behavior for database records not loaded into memory.
Microsoft docs say that:
If you want the database to also try to propagate null values to child foreign keys even when the child entity is not loaded, then use
SetNull
. However, note that the database must support this, and configuring the database like this can result in other restrictions, which in practice often makes this option impractical. This is why SetNull is not the default.
But I think it is usually normal to set FK of dependent entities to Null when the associated parent is deleted (every where in db). And also, what's those "other restrictions, which in practice often makes this option impractical.." as claimed above?