EntityFramework-Extensions icon indicating copy to clipboard operation
EntityFramework-Extensions copied to clipboard

WhereBulkContains not working with ExecuteDelete() of EF Core

Open danielisenmann opened this issue 8 months ago • 4 comments

Hi, we stumble upon the issue that WhereBulkContains doesn't work in conjunction with ExecuteDelete. It seems that WhereBulkContains doesn't return anything which can be used by ExcecuteDelete afterwards which leads to the issue that ExecuteDelete deletes the whole table.

I have written a small fiddle example of it here: https://dotnetfiddle.net/0HVPf6

We are using the latest version of EF Core Extensions (Z.EntityFramework.Extensions.EFCore 9.103.7.2) with latest version of .NET 9.

I have not seen any documentation about this issue at the moment or anything that WhereBulkContains should not be used with ExecuteDelete. Maybe I have missed it.

I know that I can use DeleteFromQueryAsync instead but I just wanted to report this issue with ExecuteDelete.

Regards Daniel

danielisenmann avatar Apr 08 '25 13:04 danielisenmann

Hello @danielisenmann,

We’ll take a look to see if it’s something we can quickly fix, but I can’t make any promises—EF Core generates the query, not us, so we might be limited in what we can do.

That said, our DeleteFromQuery, which is very similar, already works fine. You can see an example here: https://dotnetfiddle.net/bveB9S

Best regards,

Jon

JonathanMagnan avatar Apr 08 '25 21:04 JonathanMagnan

Thanks for your fast reply. At the moment we are using DeleteFromQuery because that's the only possibility to use WhereBulkContains at the moment if you want to delete filtered entities.

But thanks for letting me know that you are trying to fix it.

danielisenmann avatar Apr 09 '25 06:04 danielisenmann

Hello @danielisenmann,

After reviewing the code to make our feature compatible with ExecuteDelete, we’ve decided not to move forward with it—at least for now. The reason is that we would need to use the same strategy as our DeleteFromQuery, involving some JOIN logic. In the end, both methods would end up generating almost identical SQL.

So for the time being, we prefer to focus our efforts on bug fixes and documentation, rather than replicating a behavior that already exists and works well.

Best Regards,

Jon

JonathanMagnan avatar Apr 15 '25 15:04 JonathanMagnan

I'm totally fine with your decision and it makes sense if the SQL would be nearly identical. But you should document it that it won't work with ExecuteDelete correctly because it's deleting the whole table.

Best regards Daniel

danielisenmann avatar Apr 17 '25 16:04 danielisenmann

Hello @danielisenmann,

I forgot to close this issue. We’ve added a note in the Limitations section explaining why it’s not supported: https://entityframework-extensions.net/where-bulk-contains#what-are-the-limitations

Best Regards,

Jon

JonathanMagnan avatar Aug 26 '25 18:08 JonathanMagnan