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

Re-write cascade delete documentation #2996

Merged
merged 4 commits into from
Jan 12, 2021

Conversation

ajcvickers
Copy link
Member

@ajcvickers ajcvickers commented Jan 9, 2021

Fixes #473
Fixes #828
Fixes #998
Fixes #1926
Fixes #2367
Fixes #2426
Fixes #2906

@ajcvickers ajcvickers force-pushed the BlowTheTopOffTheStratovolcano0107 branch 4 times, most recently from acd93f8 to b36a057 Compare January 9, 2021 22:27
@ajcvickers ajcvickers requested a review from a team January 9, 2021 22:34
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complicated subject... But looks indeed much better than before. Hopefully we'll get around to improving the product support at some point.

uid: core/saving/cascade-delete
---
# Cascade Delete

Cascade delete is commonly used in database terminology to describe a characteristic that allows the deletion of a row to automatically trigger the deletion of related rows. A closely related concept also covered by EF Core delete behaviors is the automatic deletion of a child entity when it's relationship to a parent has been severed--this is commonly known as "deleting orphans".
Entity Framework Core (EF Core) represents relationships using foreign keys. An entity with a foreign key is the child or dependent entity in the relationship. This entity's foreign key value must match the primary key value (or an alternate key value) of the related principal/parent entity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Entity Framework Core (EF Core) represents relationships using foreign keys. An entity with a foreign key is the child or dependent entity in the relationship. This entity's foreign key value must match the primary key value (or an alternate key value) of the related principal/parent entity.
When using a relational database, Entity Framework Core (EF Core) represents relationships using foreign keys. An entity with a foreign key is the child or dependent entity in the relationship. This entity's foreign key value must match the primary key value (or an alternate key value) of the related principal/parent entity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also true for non-relational databases.

entity-framework/core/saving/cascade-delete.md Outdated Show resolved Hide resolved
entity-framework/core/saving/cascade-delete.md Outdated Show resolved Hide resolved
entity-framework/core/saving/cascade-delete.md Outdated Show resolved Hide resolved
> [!NOTE]
> This table is confusing and we plan to revisit this in a future release. See [GitHub Issue #21252](https://github.com/dotnet/efcore/issues/21252).

The behaviors of `ON DELETE NO ACTION` and `ON DELETE RESTRICT` in relational databases are typically either identical or very similar. Despite what `NO ACTION` may imply, both of these options cause referential constraints to be enforced. The difference, when there is one, is _when_ the database checks the constraints. This is of academic interest only for most applications since it rarely effects behavior. Check your database documentation for the specific differences between `ON DELETE NO ACTION` and `ON DELETE RESTRICT` on your database system.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is of academic interest only for most applications since it rarely effects behavior.

That may be a bit extreme - NO ACTION can be quite useful to temporary violate a deferred constraint within a transaction, in order to set the missing principal later in the same transaction (in PG and Sqlite).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about I remove "This is of academic interest only for most applications since it rarely effects behavior."?

entity-framework/core/saving/cascade-delete.md Outdated Show resolved Hide resolved
samples/core/CascadeDeletes/CascadeDeletes.csproj Outdated Show resolved Hide resolved
entity-framework/core/saving/cascade-delete.md Outdated Show resolved Hide resolved
@ajcvickers ajcvickers force-pushed the BlowTheTopOffTheStratovolcano0107 branch from e5c9ac4 to e9b7950 Compare January 12, 2021 17:30
@ajcvickers ajcvickers merged commit 6de2d9d into master Jan 12, 2021
@smitpatel smitpatel deleted the BlowTheTopOffTheStratovolcano0107 branch January 12, 2021 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment