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

Populate DbUpdateException.Entries for non-concurrency exceptions #22361

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ public override void Execute(IRelationalConnection connection)
}
catch (Exception ex)
{
throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex);
throw new DbUpdateException(
RelationalStrings.UpdateStoreException,
ex,
ModificationCommands.SelectMany(c => c.Entries).ToList());
}
}

Expand Down Expand Up @@ -291,7 +294,10 @@ public override async Task ExecuteAsync(
}
catch (Exception ex)
{
throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex);
throw new DbUpdateException(
RelationalStrings.UpdateStoreException,
ex,
ModificationCommands.SelectMany(c => c.Entries).ToList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ public void Insert_with_ValueGeneratedOnAdd_GUID_nonkey_property_throws()
Assert.Equal(default, blog.NotId);

// No value set on a required column
Assert.Throws<DbUpdateException>(() => context.SaveChanges());
var updateException = Assert.Throws<DbUpdateException>(() => context.SaveChanges());
Assert.Single(updateException.Entries);
}

public class BlogContextClientGuidNonKey : ContextBase
Expand Down Expand Up @@ -794,8 +795,10 @@ public void Insert_with_explicit_non_default_keys_by_default()
// SqlException : Cannot insert explicit value for identity column in table
// 'Blog' when IDENTITY_INSERT is set to OFF.
context.Database.CreateExecutionStrategy().Execute(
context, c =>
Assert.Throws<DbUpdateException>(() => c.SaveChanges()));
context, c => {
var updateException = Assert.Throws<DbUpdateException>(() => c.SaveChanges());
Assert.Single(updateException.Entries);
});
}

[ConditionalFact]
Expand All @@ -812,7 +815,8 @@ public void Insert_with_explicit_default_keys()
// inner exception for details.
// SqlException : Cannot insert explicit value for identity column in table
// 'Blog' when IDENTITY_INSERT is set to OFF.
Assert.Throws<DbUpdateException>(() => context.SaveChanges());
var updateException = Assert.Throws<DbUpdateException>(() => context.SaveChanges());
Assert.Single(updateException.Entries);
}

public class BlogContext : ContextBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public virtual void Exception_in_SaveChanges_causes_store_values_to_be_reverted(
new object[] { context.Entry(entity).Property(p => p.Id).CurrentValue }).Entity);
}

Assert.Throws<DbUpdateException>(() => context.SaveChanges());
// DbUpdateException : An error occurred while updating the entries. See the
// inner exception for details.
// SqlException : Cannot insert explicit value for identity column in table
// 'Blog' when IDENTITY_INSERT is set to OFF.
var updateException = Assert.Throws<DbUpdateException>(() => context.SaveChanges());
Assert.Single(updateException.Entries);

foreach (var entity in entities.Take(100))
{
Expand Down