-
Notifications
You must be signed in to change notification settings - Fork 46
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
Bahavior for Cascading deletes? #37
Comments
You have an interesting use case. Ideally the triggers library would figure out this situation and run the right triggers. I have tried to recreate your scenario with both Sqlite and SQL Server providers and I don't see the |
I don't have any simple example available, the actual use is rather complex, but basically I have one recordtype (R) that implements a many to many relationship, pointing to two parent-types (A & B). The update process is simply that I update parent type A, and in the process simply replaces the navigation collection containing R records with a new collection containing those that should be kept. In the database this ends up cleanly, the records not present in that navigation collection are removed, and any new ones are added. In triggers, I get the "Updated" trigger for the removed records, with their parent A navigation set to null. (But with the foreign key still containing the id of the parent), but not the "Deleted" trigger. I have currently figured out a workaround that recognizes that the parent navigation is set to null and that the relationship isn't optional, and that way I can see that the record needs to be deleted from my cache, but it is still confusing that it happens this way. (also, the R records have a separate DbId field (indexed integer) as primary key, in case that makes any difference) |
Actually, it is only the relation to that recordtype that I am updating that is cascading, but that shouldn't really make any difference This is how it is defined: ` public partial class OfferingEquipment internal static void Configure(ModelBuilder modelBuilder)
} |
Are triggers capable of handling the cascading delete that occurs if you remove records from a navigation collection where cascading deletes are set up? No explicit remove from the context is done, but the records missing a mandatory owner will be removed.
I am trying to catch those deletes in a Deleted trigger, but it doesn't seem that i get there. (trying to keep an in-memory cache syncronized with the DB)
Instead, it seems like the entities are showing up in the Updated trigger with the parent navigation property set to null, but this is much more complicated to handle in a generic way. (I am doing this for a number of different entitytypes, so the code in that case would have to figure out if the navigation is in fact cascading and which field it should test for null)
Running Triggers 1.1.1 with EF Core 2.2.1
The text was updated successfully, but these errors were encountered: