Skip to content
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

Stop automatically deleting orphans for optional relationships with cascade delete configured #27217

Closed
ajcvickers opened this issue Jan 19, 2022 · 2 comments · Fixed by #27557
Labels
area-change-tracking breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Member

See #27174

Cascade delete is typically used with required relationships, where a dependent cannot exist in the database without a principal. In this case, delete orphans behavior makes sense. However, if cascade delete is used with optional relationships, then the dependent can still exist without the principal, which means it probably doesn't make sense to delete orphans automatically.

@ajcvickers ajcvickers self-assigned this Jan 19, 2022
@ajcvickers ajcvickers added this to the 7.0.0 milestone Jan 22, 2022
ajcvickers added a commit that referenced this issue Mar 2, 2022
…de deletes

Fixes #27217
Fixes #27218

The 5.0/6.0 behavior here is:
- Orphans are deleted if the relationship is severed by navigation property
- Orphans are not deleted if the relationship is severed by setting the FK to null

This change means orphans are not deleted in either case. The change that causes this to happen is to not set a conceptual null for a nullable FK property. Deletion can still be forced by explicitly forcing a conceptual null or just by setting the dependent state explicitly to Deleted.
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Mar 2, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview3 Mar 15, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview3, 7.0.0 Nov 5, 2022
@stevendarby
Copy link
Contributor

stevendarby commented Dec 7, 2022

Hi @ajcvickers I've tried reading this over a few times and feel I'm missing something. Are you saying that if the relationship is optional and cascade delete has been configured, it will no longer cascade the delete? Why would it not respect the delete behaviour configured for the relationship? Sorry if I've misunderstood.
Sorry, this finally clicked just after I posted. I think this is about when the relationship is severed, not when the principal is deleted.

@archer87pl
Copy link

Please take a look at issue #33610
That change is causing strange behaviour for simple updates and there should be an option to change default behaviour like it was in EF Core 6.0

@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-change-tracking breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants