299
CHAPTER 7 | Implement resilient applications
// Use of an EF Core resiliency strategy when using multiple DbContexts
// within an explicit BeginTransaction():
// https://learn.microsoft.com/ef/core/miscellaneous/connection-resiliency
var
strategy = _context.
Database
.
CreateExecutionStrategy
();
await strategy.
ExecuteAsync
(
async
() =>
{
await
using
var
transaction = await _context.
Database
.
BeginTransactionAsync
();
await
action
();
await transaction.
CommitAsync
();
});
}
}
Dostları ilə paylaş: