Code: Select all
try
{
_unitOfWork.BeginTransaction();
response = _unitOfWork.DeclarationRepository.ChangeDeclarationSectionFormsState_1Async(declarationId,sectionId, newFormState);
// we need this save changes here so that the intermediate result
// is available for UpdateDeclarationStatusIfApplicableAsync to read the
// statuses of the forms even if they are not yet committed to the db
await _unitOfWork.SaveChangesAsync(cancellationToken);
//throw new Exception();
DeclarationStatusTypes newDeclarationStatus = Mappers.FormStateToDeclarationStatusMapper[newFormState];
await _unitOfWork.DeclarationRepository.UpdateDeclarationStatusIfApplicableAsync(declarationId, newDeclarationStatus, cancellationToken);
await _unitOfWork.CommitAsync(cancellationToken);
}
catch
{
_unitOfWork.Rollback();
throw;
}
Die Methode versucht, Zwischendatensätze wie folgt zu lesen:
Code: Select all
StringBuilder query = new StringBuilder("SELECT CAST(CASE WHEN EXISTS (");
foreach (string formTable in FormDbTableMapper.Values)
{
query.AppendLine($"SELECT 1 AS [Value] FROM {Constants.Schema.DEC}.{formTable} WHERE DeclarationId=@DeclarationId AND IsActive=1 AND State@State");
query.AppendLine(" UNION ");
}
// remove the last UNION
query.Length -= 8;
query.AppendLine(") THEN 0 ELSE 1 END AS BIT) AS [Value]");
SqlParameter declarationIdParam = new SqlParameter("DeclarationId",declarationId);
SqlParameter stateParam = new SqlParameter("State", (int)state);
return await dbContext.Database.SqlQueryRaw(query.ToString(), new[] { declarationIdParam, stateParam }).FirstOrDefaultAsync();
Meine Frage: Ist es ein Anti-Pattern oder falsch, solche Sicherungspunkte vor dem Transaktions-Commit zu erstellen?
Mobile version