Fanray Ep07 - Entity Framework Core: Nullable Foreign Key, Cascade Delete, Entity Tracking

Опубликовано: 31 Июль 2026
на канале: Ray Fan
3,294
10

Nullable FK and Cascade Delete

Entity Framework won't generate Cascade Delete for a Nullable FK, that is the case for Category and Post. Therefore deleting a category won't delete its associated posts, it will set those posts' CategoryId to null. In that scenario I will reassign a default category to those posts.

Entity Tracking vs. No-Tracking

https://docs.microsoft.com/en-us/ef/c...
Tracking means you can make changes to those entity instances and have those changes persisted by SaveChanges().
No-Tracking is good for read-only scenarios. They are quicker to execute because there is no need to setup change tracking information.

1-To-Many, Category and Post design decisions

No Get operation for individual category
[NotMapped] on Count property


Github Repo
https://github.com/FanrayMedia/Fanray