How to do cascade delete from code first , for two table which has fk to same table

I have two table one is Table A and another one is Table B both have fkMedicalInsurance column which is nullable

there is medical insurance table which is child table to above two able

As i deleting Related person , medical insurance doesn't get deleted , even though On Delete - cascade is set

How to do this using code first mapping ?

June 18th, 2015 5:39am

Hi try to recreate the ON delete cascade foriegn key on medical insurance table.
Free Windows Admin Tool Kit Click here and download it now
June 18th, 2015 5:51am

I'm not sure from your question exactly what the schema of your tables looks like, but if it is something like

Create Table FooMedicalInsurance(MedID int Primary Key)
Create Table FooTableA(TableAID int Primary Key, 
    fkMedicalInsurance int Foreign Key References FooMedicalInsurance On Delete Cascade)
Create Table FooTableB(TableAID int Primary Key, 
    fkMedicalInsurance int Foreign Key References FooMedicalInsurance On Delete Cascade)

then deleting from FooTableA or FooTableB will have no affect on FooMedicalInsurance.  But deleting row(s) from FooMedicalInsurance will delete the corresponding row(s) from FooTableA and FooTableB

Tom


June 18th, 2015 8:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics