'Delete table records except primary table where tables are linked with Foreign key constraints
I have 6 tables (Let's say A,B,C,D,E,F).
A is the main table - let AP be the primary key. Now, B and C are having AP as their foreign key. B's primary key is BP and C is primary key is CP. Now D and E are having BP as it's foreign key. And, finally F is having CP as it's Foreign key. These are all 1-many relationships.
So now the problem statement is: I get a ID which can have multiple records in table A ( Main table). I need to find the latest record record with that ID, and the corresponding Primary key of that record. Then I need to delete the records corresponding to that primary key (B,C,D,E,F). Note: I won't delete the record from main table(A). I will just update a row in that table.
- What would be the best approach to solve this problem using Entity Framework Core?
- Cascade delete might delete all the records.
- How to get that Primary key of that latest record.
Want to do it without multiple DB connection opening.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
