Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow cascade delete timing to be configured
Fixes #10114 Allows timing cascade delete (i.e. delete of dependent on principal deletion) and delete orphans (i.e. delete of dependent on severing its relationship to the principal) to be configured as: * Immediate: Dependents changed to Deleted immediately, or at least at the next DetectChanges * OnSaveChanges: Dependents are not changed to Deleted until SaveChanges is called * Never: Cascades don't happen automatically. They can be triggered by a new method: `context.ChangeTracker.CascadeChanges()` The default for both has been changed to `Immediate` which is a breaking change, but likely a better default because: * Auditing in overridden SaveChanges will now report anything that will be deleted * Data binding will reflect the changes immediately However, deleting orphans can be more difficult. This doesn't appear to be a major problem in EF Core because we don't aggressively graph shred, we don't typically have entities that handle their own fixup, and conceptual nulls still exist to allow transitionary states. Note that EF6 does not support deleting orphans, which means the behavior here with both set to Immediate is not quite the same as the default behavior of EF6.
- Loading branch information
1 parent
40230a1
commit e90bd07
Showing
27 changed files
with
5,380 additions
and
1,488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.ChangeTracking | ||
{ | ||
/// <summary> | ||
/// Defines different strategies for when cascading actions will be performed. | ||
/// See <see cref="ChangeTracker.CascadeDeleteTiming" /> and <see cref="ChangeTracker.DeleteOrphansTiming" />. | ||
/// </summary> | ||
public enum CascadeTiming | ||
{ | ||
/// <summary> | ||
/// Cascading actions are made to dependent/child entities as soon as the principal/parent | ||
/// entity changes. | ||
/// </summary> | ||
Immediate, | ||
|
||
/// <summary> | ||
/// Cascading actions are made to dependent/child entities as part of <see cref="DbContext.SaveChanges()" />. | ||
/// </summary> | ||
OnSaveChanges, | ||
|
||
/// <summary> | ||
/// Cascading actions are never made automatically to dependent/child entities, but must instead | ||
/// be triggered by an explicit call. | ||
/// </summary> | ||
Never | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.