Steven Steven - 1 year ago 119
ASP.NET (C#) Question

Cascading delete in Entity Framework

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

enter image description here

As you can see, there are two OnDelete properties: End1 OnDelete and End2 OnDelete

Which one do I need to set to Cascade?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download