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

Document breaking(ish) changes around DeleteBehavior #3375

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions entity-framework/core/saving/cascade-delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Cascade Delete - EF Core
description: Configuring cascading behaviors triggered when an entity is deleted or severed from its principal/parent
author: ajcvickers
ms.date: 01/07/2021
ms.date: 08/10/2021
uid: core/saving/cascade-delete
---
# Cascade Delete
Expand Down Expand Up @@ -466,17 +466,16 @@ The following table shows the result of each `OnDelete` value on the foreign key
| DeleteBehavior | Impact on database schema
|:----------------------|--------------------------
| Cascade | ON DELETE CASCADE
| Restrict | ON DELETE NO ACTION
| Restrict | ON DELETE RESTRICT
| NoAction | database default
| SetNull | ON DELETE SET NULL
| ClientSetNull | ON DELETE NO ACTION
| ClientCascade | ON DELETE NO ACTION
| ClientSetNull | database default
| ClientCascade | database default
| ClientNoAction | database default

> [!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` (the database default) 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. Check your database documentation for the specific differences between `ON DELETE NO ACTION` and `ON DELETE RESTRICT` on your database system.

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. Check your database documentation for the specific differences between `ON DELETE NO ACTION` and `ON DELETE RESTRICT` on your database system.
SQL Server doesn't support `ON DELETE RESTRICT`, so `ON DELETE NO ACTION` is used instead.

The only values that will cause cascading behaviors on the database are `Cascade` and `SetNull`. All other values will configure the database to not cascade any changes.

Expand Down
53 changes: 47 additions & 6 deletions entity-framework/core/what-is-new/ef-core-6.0/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,63 @@
title: Breaking changes in EF Core 6.0 - EF Core
description: Complete list of breaking changes introduced in Entity Framework Core 6.0
author: ajcvickers
ms.date: 01/12/2021
ms.date: 08/10/2021
uid: core/what-is-new/ef-core-6.0/breaking-changes
---

# Breaking changes in EF Core 6.0

The following API and behavior changes have the potential to break existing applications updating to EF Core 6.0.0.

> [!NOTE]
> Coming soon!

## Summary

| **Breaking change** | **Impact** |
|:--------------------------------------------------------------------------------------------------------------------------------------|------------|

## Medium-impact changes
| [Cleaned up mapping between DeleteBehavior and ON DELETE values](#on-delete) | Low |

## Low-impact changes

<a name="on-delete"></a>

### Cleaned up mapping between DeleteBehavior and ON DELETE values

[Tracking Issue #21252](https://github.com/dotnet/efcore/issues/21252)

#### Old behavior

Some of the mappings between a relationship's `OnDelete()` behavior and the foreign keys' `ON DELETE` behavior in the database were inconsistent in both Migrations and Scaffolding.

#### New behavior

The following table illustrates the changes for **Migrations**.

OnDelete() | ON DELETE
-------------- | ---------
NoAction | NO ACTION
ClientNoAction | NO ACTION
Restrict | RESTRICT
Cascasde | CASCADE
ClientCascade | ~~RESTRICT~~ **NO ACTION**
SetNull | SET NULL
ClientSetNull | ~~RESTRICT~~ **NO ACTION**

The changes for **Scaffolding** are as follows.

ON DELETE | OnDelete()
--------- | ----------
NO ACTION | ClientSetNull
RESTRICT | ~~ClientSetNull~~ **Restrict**
CASCADE | Cascade
SET NULL | SetNull

#### Why

The new mappings are more consistent. The default database behavior of NO ACTION is now preferred over the more restrictive and less performant RESTRICT behavior.

#### Mitigations

The default OnDelete() behavior of optional relationships is ClientSetNull. Its mapping has changed from RESTRICT to NO ACTION. This may cause a lot of operations to be generated in your first migration added after upgrading to EF Core 6.0.

You can choose to either apply these operations or manually remove them from the migration since they have no functional impact on EF Core.

SQL Server doesn't support RESTRICT, so these foreign keys were already created using NO ACTION. The migration operations will have no affect on SQL Server and are safe to remove.