I want to delete an entry from my Database but it says it can’t because another table has referenced its id. The table I’m deleteing from is:
Packages(packageID(PRIMARY), package_name, etc. . . .)
The table I want to cascade delete from is
PackageVariant(packageID(FOREIGN), variantID(FOREIGN)) //those foreign keys combine to make PRIMARY composite key
On deletion of an entry from PackageVariant I want to cascade delete the variants associated:
Variant(variantID(PRIMARY), variant_name, etc . . .)
And thats as far as I want the cascade to go.
Now I have an Entity Framework model setup and working correctly, I have the database setup and working correctly. So how do I go about changing both or either of them so that this cascade delete works?
I also have a PackageVariantProduct Database Diagram made.
Thanks
Cascade delete is handled on referential constraint in the database so you just need to set up
On Deleterule toCascade. The problem is that cascading can happen only from principal to dependent entity. So if you expect that deleting (even cascaded deleting) fromPackageVariantwill delete eitherPackagesorVariants, it will not work. You will have to use a database trigger for that if you really need it.