sql server - Delete using RemoveRange when FK exists -


i know comes lot, wondering how getting list of entities delete has impact on being successful or not.

in code below, im getting error complaining conflicting fk constraint.
in case table paymentinvoice fk reference warehousestatementbatchpayment in turn has fk referece warehousestatementbatch. should able delete records child table (paymentinvoice in case). understand if deleting 1 of other tables, since records in paymentinvoice still refer deleting. not in case?

since im fetching list of paymentinvoice records joining on other two, affect ability delete them?

                        var paymentinvoicelist = (from b0 in ctx.paymentinvoices                                                     join c0 in ctx.warehousestatementbatchpayments on b0.warehousestatementbatchpaymentid equals c0.id                                                     join d0 in ctx.warehousestatementbatches on c0.warehousestatementbatchid equals d0.id                                                     d0.id == b0.id                                                     select b0)                                             .tolist();                         ctx.paymentinvoices.removerange(paymentinvoicelist); 

the error get: delete statement conflicted reference constraint \"fk_paymentinvoice_warehousestatementbatchpayment\"

that fk exists in paymentinvoice table.

also, checked other possible dependencies on paymentinvoice table , there none (other views , stored procedures). of stored procedures have been pulled data model function imports, thats not immediate concern evident error message complaining fk constraint.

what else should check?


Comments