✅ transaction in transaction issue
I have this error:
should
The connection is already in a transaction and cannot participate in another transaction.
My code:
public override async Task<OperationResult> AddOrUpdateWorkingTasksAsync(
IReadOnlyList<Infrastructure.Data.WorkingTask> workingTasks,
EventHandlingContext context)
{
var transaction = await BeginTransactionAsync(context).ConfigureAwait(false);
await using(transaction)
{
foreach(var workingTask in workingTasks)
{
var existTask = await FindAsync(workingTask.Id, context).ConfigureAwait(false);
if(existTask != null)
await UpdateAsync(workingTask, context).ConfigureAwait(false);
else
await AddAsync(workingTask, context).ConfigureAwait(false);
}
await eventDispatcher.WorkingTasksUpdatedAsync(workingTasks!, context).ConfigureAwait(false);
await transaction.CommitAsync(context.CancellationToken).ConfigureAwait(false);
}
return OperationResult.Success;
}
public override async Task<OperationResult> AddOrUpdateWorkingTasksAsync(
IReadOnlyList<Infrastructure.Data.WorkingTask> workingTasks,
EventHandlingContext context)
{
var transaction = await BeginTransactionAsync(context).ConfigureAwait(false);
await using(transaction)
{
foreach(var workingTask in workingTasks)
{
var existTask = await FindAsync(workingTask.Id, context).ConfigureAwait(false);
if(existTask != null)
await UpdateAsync(workingTask, context).ConfigureAwait(false);
else
await AddAsync(workingTask, context).ConfigureAwait(false);
}
await eventDispatcher.WorkingTasksUpdatedAsync(workingTasks!, context).ConfigureAwait(false);
await transaction.CommitAsync(context.CancellationToken).ConfigureAwait(false);
}
return OperationResult.Success;
}
public async Task AddAsync(TEntity entity, TContext context)
{
var transaction = await rootRepository.BeginTransactionAsync(context).ConfigureAwait(false);
await using(transaction)
{
await AddCoreAsync(entity, context).ConfigureAwait(false);
await transaction.CommitAsync(context.CancellationToken).ConfigureAwait(false);
}
}
public async Task AddAsync(TEntity entity, TContext context)
{
var transaction = await rootRepository.BeginTransactionAsync(context).ConfigureAwait(false);
await using(transaction)
{
await AddCoreAsync(entity, context).ConfigureAwait(false);
await transaction.CommitAsync(context.CancellationToken).ConfigureAwait(false);
}
}
AddAsync
contain a transaction?3 Replies