BulkDelete behaviour unexpected
Hi,
I have another problem with BulkDelete when including the graph. I have attached a screenshot that outlines the structure of my entities.
CASE 1: BULKDELETE WITH INCLUDE GRAPH
I query my the table of Entity9 (blue) and use Include() and ThenInclude to specify the relations with its children. When I call BulkDelete,
I expect the following colours to be deleted:
- Blue
- Green
- Yellow
But instead, the following colours are deleted:
- Blue
- Green
- Red
CASE 2: BULKDELETE WITHOUT INCLUDE GRAPH I use the same query as case 1.
I expect the following colours to be deleted:
- Blue
- Yellow
But instead, the following colours are deleted:
- Blue
ADDITIONAL INFO
I therefore conclude that IncludeGraph = true works both ways (towards its parents and childs). For me, this is unexpected. I only want to target the children. How do I specify this? And why are my yellow entities not removed?
I hear you thinking, are there relations between the yellow entities and the red entities? Yes, there are. They are optional, cascase deletion is disabled and they are not included in the inclusion query.
When I use RemoveRange, the blue and green entities are removed from CASE 1. For me, this is still unexpected, because this means I have to manually query the yellow entities. And since I cannot query this easily, it means I have to load them into memory. My main motivation for this update was performance, and with these issues, I am negating all the performance gains that I intended :( What do I do? I feel that this is a bug in EFCore.BulkExtensions.
Not sure about this, if figure out something improvement will write it. Maybe try using BulkRead and BulkDelete for each table without IncludeGraph, as that is very specific feature that was added as a PR and does not cover all situations.