Breeze / breeze-client

Breeze for JavaScript clients
MIT License
38 stars 16 forks source link

Handling deleted and updated entities in the same saveChanges call when cascade delete is configure in the db #62

Open graphicsxp opened 2 years ago

graphicsxp commented 2 years ago

I'm facing an issue when saving parent and child entities at the same time :

Let's say I have the following entities:

Publication { id: guid; publicationLvs: PublicationLv [ ] } PublicationLv { id: guid; publicationId: guid }

I delete the parent entity :

publication.entityAspect.setDeleted();

Then when I call save changes, the payload looks like this :
image

So Publication is deleted and PublicationLv is modified with its foreign key PublicationId set to a 0 guid.

When saveChanges is called on the server (Entity Framework Core), I get a 500 :

image

It seems breeze doesn't know about the cascade delete configured in the DB. So when it tries to update publicationLv, it was already deleted when the Publication was deleted.

Is this a configuration issue or a bug ? Here's my metadata :

image

image

graphicsxp commented 2 years ago

I detach all the children entities before deleting the Publication. It works fine. But this Stackoverflow answer suggests that this would have been implemented in breeze at some point (7 years ago). Is it the case ? https://stackoverflow.com/questions/26724082/cascade-delete-not-working-with-breeze