If you call InsertAllAsync method under TransactionScope, Task
It is used in the following environment.
-.NET Core 3.1
using (var ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions(), TransactionScopeAsyncFlowOption.Enabled))
{
var dbConnection = factory.CreateConnection();
if (dbConnection == null)
return;
dbConnection.ConnectionString = connectionStrings;
await dbConnection.EnsureOpenAsync();
var timestamp = DateTimeOffset.UtcNow;
var defaultTimeStamp = new DateTimeOffset(new DateTime(1900, 1, 1));
// OK
await dbConnection.InsertAsync(new User
{
Id = 1,
Name = "user1",
Email = "email",
CreatedAt = timestamp,
UpdatedAt = timestamp,
DeletedAt = defaultTimeStamp
});
// NG Throws System.NullReferenceException
await dbConnection.InsertAllAsync(new[]
{
new User { Id = 2, Name = "user2", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 3, Name = "user3", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 4, Name = "user4", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 5, Name = "user5", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 6, Name = "user6", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 7, Name = "user7", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 8, Name = "user8", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 9, Name = "user9", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp},
new User { Id = 10, Name = "user10", Email = "email", CreatedAt = timestamp, UpdatedAt = timestamp, DeletedAt = defaultTimeStamp}
});
ts.Complete();
await dbConnection.CloseAsync();
}
I had replicated this bug on the Core line. It is very unfortunate, we had removed it when we migrated from the old code line (see this line in to the new code line (see this line).
The fix will be issued on the new release together with MergeAll and UpdateAll methods (to all supported RDBMS). Mind if you can share when do you need this? Thanks
@karuakun - this bug is now fixed and is a part of the latest deployment (RepoDb.MySqlConnector (v1.0.4)). Would you be able to validate in your side? Thanks
> Install-Package RepoDb.MySqlConnector -version 1.0.4
Thanks for fixing it!
I confirmed that it was fixed.
Closing this ticket now. Thanks