Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow delete fixup and cascade timing to be configured #10114
Comments
This comment has been minimized.
This comment has been minimized.
Another use case here: Being able to detect the entities that were removed (possibly by getting a tree of them prior to SaveChanges) so that you can perform an action afterwards. For example, removing referenced objects from the filesystem or S3. |
This comment has been minimized.
This comment has been minimized.
Should the same behaviour occur when query filters are applied such as when doing a soft delete? For example in a Blog/Posts scenario, if a Post is soft deleted (using shadow property and query filter), the Post no longer appears in the DbSet, but I still see it in the navigation collection of the Blog. |
This comment has been minimized.
This comment has been minimized.
My 2 cents - my primary interest is in soft delete. I check which entities have been deleted, and instead set an IsDeleted=true and change them to Modified. It would suffice for me to just get some kind of callback where I can do this logic. Since you said the current logic is in order to do the right thing for reparenting, and prevent graph shredding, I don't necessarily want that just undone in the general case. All I need is some point where I get the REAL state of the objects prior to the DB save... |
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.
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.
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.
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.
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.
This comment has been minimized.
This comment has been minimized.
Re-opening to ensure breaking change is announced. |
Currently:
However, there are scenarios where it is useful for these things to happen at different times:
There are a few things we could do: