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

GlobalUpdateFailed not triggered when there are more than 1 entries in the change tracker #60

Open
soniachikh opened this issue Feb 8, 2021 · 2 comments

Comments

@soniachikh
Copy link

We are using .netcore 2.2
We are adding a trigger to the updating action and another trigger (GlobalUpdateFailed) to undo what the updating trigger does when the DB Save fails.  We try to attempt a DB save with a read only dbuser it throws a DBUpdateException but when RaiseFailedEventsAsync is called there is a check for the number of entries in the changetracker and if it is not 1 it exits without calling the GlobalUpdateFailed trigger.   Can you please help us understand the reason for the check.

In our application, we try to make our DB changes transactional, in this one action we indeed change a few DB entries but we only call DB save once to ensure the DB integrity and increase performance. 

@NickStrupat
Copy link
Owner

Do you have a minimal sample project which reproduces the issue? You can post it on this issue.

@jeremy-lafond
Copy link

jeremy-lafond commented Feb 25, 2021

The following method located in "EntityFramework.Triggers/src/EntityFrameworkCore.Triggers/TriggerInvokerAsync.cs" returns false instead of await RaiseFailedEventsInternalAsync(context, serviceProvider, entries, dbUpdateException); when the number of entries is not 1. However our entries are greater than 1. Therefore we were wondering why you are checking the number of entries since it would be important for us to have the revert for entries that are greater than 1.

public async Task<Boolean> RaiseFailedEventsAsync(DbContext dbContext, IServiceProvider serviceProvider, DbUpdateException dbUpdateException)
		{
			var context = (TDbContext)dbContext;

			IEnumerable<EntityEntry> entries;

			if (dbUpdateException.Entries.Any())
			{
				entries = dbUpdateException.Entries;
			}
			else
			{
				entries = dbContext.ChangeTracker.Entries().ToArray();
				if (entries.Count() != 1)
				{
					return false;
				}
			}
			return await RaiseFailedEventsInternalAsync(context, serviceProvider, entries, dbUpdateException);
		}

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

No branches or pull requests

3 participants