zzzprojects / GraphDiff

GraphDiff is a library that allows the automatic update of a detached graph using Entity Framework code first.
https://entityframework-graphdiff.net/overview
MIT License
333 stars 101 forks source link

How can I configure to cascade the deletion of a doubly-nested parent child heirarchy? #120

Closed ghost closed 9 years ago

ghost commented 9 years ago

Here's my schema.

image

I've set up my graph diff like so.

var inspect = ctx.UpdateGraph(entityOrder, orderProduct => orderProduct .OwnedCollection(p => p.OrderProducts, op => op .OwnedCollection(attr => attr.OrderProductAttributes) .OwnedCollection(discount => discount.OrderProductDiscounts)) .OwnedCollection(orderDiscount => orderDiscount.Discounts) .OwnedCollection(cpi => cpi.CustomerProvidedItems) .OwnedCollection(documents => documents.Documents) ); If I attempt to remove an orderProduct that has orderProductAttributes associated with it, update the graph and then save. It throws the following exception.

The relationship could not be changed because one or more of the foreign-key properties is non-nullable.

I'm sure it's something silly associated with the attribute, but I can't seem to figure it out.

ghost commented 9 years ago

If anyone has the same issue, I wasn't able to resolve the issue even with the latest dev build. I ended up just detecting if an object was removed and removing all children before calling UpdateGraph. It still handles adds and updates nicely, but child deletes fail frequently.

rwdalpe commented 9 years ago

Is that relationship's foreign key configured to cascade on delete?

lopezcjf commented 9 years ago

Facing the same issue here... Did you find any solution to this?

ghost commented 9 years ago

Yes, you have to cascade on delete.