I have Child table that has foreign keys that reference two other tables, Parent1 & Parent2 (these are not the real names of these tables). Parent1 & Parent2 both have a one-to-many relationship with a Grandparent. The Child table is a join table establishing a many-to-many relationship between Parent1 and Parent2, but is exposed as its own "mapping entity" to Breeze.
I have cascade delete set on both of these foreign keys and when I delete a row in either the Parent1 or Parent2 tables from within SQL Server Management Studio, the cascade works properly and the corresponding rows in the Child table are deleted.
However when I execute the following code in my application using Breeze
function removeParent1(grandParent, parent1) {
var index = grandParent.parent1s.indexOf(parent1);
grandParent.parent1s.splice(index, 1);
parent1.entityAspect.setDeleted();
}
I receive the following exception.
An exception of type 'System.Exception' occurred in Breeze.ContextProvider.dll but was not handled in user code
Additional information: The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Child_dbo.Parent1_Parent1Id". The conflict occurred in database "DB", table "dbo.Parent1", column 'Id'.
The statement has been terminated.
I cannot figure out what's going on. Is Breeze attempting to update the Child row with a NULL foreign key?