I have a transaction where I want to save to SQL Server database some data then do some actions that I cannot redo like sending email, publish a message... etc.
And I wonder if it is possible for an EF Core transaction with a SQL Server Provider to fail event if the context saved successfully the data (it can be one or multiple calls to SaveChanges)
using (var tran = _context.Database.BeginTransaction())
{
try
{
Behaviour behaviour = new Behaviour(request.Kind, request.Label, request.Verb, request.Units, request.Cycles);
_context.BehaviourSet.Add(behaviour);
// A- other code here that adds entities to the context
// B- Save everything...
await _context.SaveChangesAsync(cancellationToken);
// C- Create and publish events to a store or some other non-transactional actions
// D- I wonder if this transaction can fail even if the SaveChanges is successful
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
// E- logging and other stuff
}
}