Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A failed bulk insert or update does not (always) tell which entities failed #555

Open
isak1080 opened this issue Nov 3, 2023 · 1 comment
Assignees

Comments

@isak1080
Copy link

isak1080 commented Nov 3, 2023

Description

During (some) failed updates, notably where the concurrency checks fail, the thrown exception has a list of entities that failed, making it very easy to retry the update with the failing entities removed.

For inserts (which by definition cannot have concurrency issues) or updates that fails due to a foreign key constraint violation for example, no such information is provided.

(Related issue: #284)

The reason I would like this is that I often do bulk updates and inserts and if they fail, I want to retry the operation with the subset of items that can be inserted/updated.

The workaround now is to either manually try to find the bad entities (very domain specific code) or retry the operation one by one, with possibly horrible performance.

Exception

The exception we get today is dependent on provider, but for me (using SQL Server in Azure) I get a SqlException with a "The MERGE statement conflicted with the FOREIGN KEY constraint..." error message. Nothing in the exception tells me which entity failed.

Fiddle or Project

This shows the problem: https://dotnetfiddle.net/DueeE4

Further technical details

  • EF version: [EF Core v7.0.13]
  • EF Extensions version: [EFE Core v7.100.0.0]
  • Database Server version: [Azure SQL Server]
@JonathanMagnan
Copy link
Member

JonathanMagnan commented Nov 13, 2023

Hello @isak1080 ,

Sorry for the very late answer.

This one is a very frequent request. Unfortunately, we are limited with the information SQL Server provides us, and at this moment, there is no way to have information about only which entities have failed. Only this general error is thrown by SQL Server.

I added in our backlog a method like ValidateEntities which will not save but return all entities in error due to a foreign key constraint or any other reason that we can validate on our side.

I cannot promise anything yet but that is surely something the next time we will choose some new options/methods to add that we will consider.

Feel free to ask for an update in 2024, it always help to make the feature happens ;)

Best Regards,

Jon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants