So I have two tables, Invoices and InvoiceItems. When I delete an Invoice, I'd like all the related InvoiceItems to be deleted as well.
I updated the relationship in SQL Server to do a cascading delete when I delete an Invoice. Entity Framework didn't recognize that change, however, but I've read that I need to manually update my EDMX to do the cascading delete.
Well in the design view of my EDMX, I clicked on the relationship between the two tables, and checked the properties to try and set my cascading delete
As you can see, there are two OnDelete properties: End1 OnDelete and End2 OnDelete
Which one do I need to set to Cascade?
I was initially confused about this as well, and the reason was that I wasn't sure of what whether it was the field Navigation Property or the field Role Name that described what object an end represented, making an answer as Devidigitals ineffective.
And the answer to that is that a end is described by the field role name.
So if we know that we want to delete all InvoiceItems for a Invoice when the invoice in question gets deleted, we probably know that we should set the OnDelete for the Invoice, and to find the specific end that represents the invoice in the relation, search for the end where the role name is "Invoice". In the above example, that is End1.
This might be obvious if you know it, but not if you don't.
If End1 is the principal of the relationship (I.e your invoice which has invoice items) then it makes sense for it to cascade deletes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With