Текущая TransactionScope уже завершена ошибка после преобразования в. net core 3.1 - PullRequest
0 голосов
/ 30 апреля 2020

После обновления до 3.1 мы получаем сообщения об ошибках, в которых говорится:

System.InvalidOperationException: текущий TransactionScope уже завершен.

Единственное реальное изменение, которое мы сделали к этому процессу следует перейти от способа использования операторов 2.x с квадратными скобками к способу использования операторов 3.x без квадратных скобок (как рекомендуется). Мы делаем что-то не так?

Текущий путь:

// As multiple copies of this service can be running at once, we should lock the table while we flag the messages to be worked on
using var transactionScope = new TransactionScope(TransactionScopeOption.Required, 
              new TransactionOptions() 
              { IsolationLevel = IsolationLevel.ReadCommitted });
messagesToProcess = context.InboundMessageQueueRecords.Where(x => x.State == QueueMessageState.New)
          .OrderBy(x => x.Added)
          .Take(NUMBER_OF_MESSAGES_TO_PROCESS).ToList();
// Flag them as in progress
messagesToProcess.ForEach(x => x.State = QueueMessageState.InProgress);
context.SaveChanges();
transactionScope.Complete();

Старый путь:

// As multiple copies of this service can be running at once, we should lock the table while we flag the messages to be worked on
using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, 
              new TransactionOptions() 
              { IsolationLevel = IsolationLevel.ReadCommitted }))
{
  messagesToProcess = context.InboundMessageQueueRecords.Where(x => x.State == QueueMessageState.New)
            .OrderBy(x => x.Added)
            .Take(NUMBER_OF_MESSAGES_TO_PROCESS).ToList();
  // Flag them as in progress
  messagesToProcess.ForEach(x => x.State = QueueMessageState.InProgress);
  context.SaveChanges();
  transactionScope.Complete();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...