So here are 3 tables I’m working with:

I want to delete everything in the ClaimCodingProcedureCodeModifierXref table and all the related rows in ProcedureCodeModifier from a specific ClaimCodingID. Here is my code so far:
using (HCCustDataEntities hc = new HCCustDataEntities())
{
var result = (from CPC in hc.ClaimCodingProcedureCodeModifierXrefs
where CPC.ClaimCodingID == claimCodingID
select CPC);
foreach (var item in result)
{
hc.DeleteObject(item);
}
}
But only data from the Xref table gets deleted. Why doesn’t EF delete the related rows as well?
Use
CASCADE DELETEin your relation ship. Entity framework will automaticaly delete the detail / child object when you delete the master record. You dont need to explicitly delete the child records in your relatioship yourself.