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

Fails when BulkDelete more than one Db Class object. #1702

Open
x2d7751347m opened this issue Mar 8, 2025 · 1 comment
Open

Fails when BulkDelete more than one Db Class object. #1702

x2d7751347m opened this issue Mar 8, 2025 · 1 comment

Comments

@x2d7751347m
Copy link

Describe the bug

Fails when BulkDelete more than one Db Class object.

The object fails equally whether it is a value read from the DB or a randomly generated value. I debugged and verified that all properties of the entitiesToDelete object are fine.

I have identified the cause of the failure as when PK and unique key are present together in the DB.

Currently, pk is set on the 'id' column which is long, auto increment, and the unique key is set on the name column which is string.
The bulk delete is executed normally if I remove the unique key of the 'name' column.

In the same environment, BulkInsert/BulkUpdate works fine.

Example:
await context.BulkDeleteAsync(entitiesToDelete, cancellationToken: ct);
StackTrace:
MySqlConnector.MySqlException (0x80004005): 2 rows were copied to table_nameTemp5c0673f5 but only 1 was inserted. at MySqlConnector.MySqlBulkCopy.WriteToServerAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in //src/MySqlConnector/MySqlBulkCopy.cs:line 347 at MySqlConnector.MySqlBulkCopy.WriteToServerAsync(DataTable dataTable, CancellationToken cancellationToken) in //src/MySqlConnector/MySqlBulkCopy.cs:line 148 at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.InsertAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, Action1 progress, Boolean isAsync, CancellationToken cancellationToken) at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.InsertAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, Action1 progress, Boolean isAsync, CancellationToken cancellationToken) at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.InsertAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, Action1 progress, CancellationToken cancellationToken) at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.MergeAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, OperationType operationType, Action1 progress, Boolean isAsync, CancellationToken cancellationToken) at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.MergeAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, OperationType operationType, Action1 progress, Boolean isAsync, CancellationToken cancellationToken) at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.MergeAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, OperationType operationType, Action1 progress, CancellationToken cancellationToken) at EFCore.BulkExtensions.SqlBulkOperation.MergeAsync[T](DbContext context, Type type, IEnumerable1 entities, TableInfo tableInfo, OperationType operationType, Action1 progress, CancellationToken cancellationToken) at EFCore.BulkExtensions.DbContextBulkTransaction.ExecuteAsync[T](DbContext context, Type type, IEnumerable1 entities, OperationType operationType, BulkConfig bulkConfig, Action1 progress, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__81.<b__8_0>d.MoveNext()
`

To Reproduce
Table with column 'A' that is long, auto-increment, pk and column 'B' that is string, unique key, when bulk-delete with 2 or more corresponding table objects: Failed.

Afterward, delete the unique key from column 'B' and it works fine.
I tried inserting an index as well, and the BulkDelete method works fine. The problem seems to be with the unique key.

Expected behavior
DB objects with the same PK as a given set of objects are deleted normally.

Technical details (please complete the following information):

Database server version: [MariaDB 11.6.2]
Operating system: [Windows 10]
Other technical details: [ASP.NET Core 9.0.2, efcore.bulkextensions.mysql\9.0.0-rc.1, mysqlconnector\2.4.0, Pomelo.EntityFrameworkCore.MySqlPomelo.EntityFrameworkCore.MySql, 9.0.0-preview.3.efcore.9.0.0]
Additional context
It is difficult to determine if this is an issue with mysqlconnector or ef core. If it's a problem with another package, I'll open an issue there.

@x2d7751347m
Copy link
Author

x2d7751347m commented Mar 9, 2025

Same issue with BulkSaveChangesAsync on delete

context.RemoveRange(entities)
await context.BulkSaveChangesAsync()

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

1 participant