I have an Oracle database and I am using Oracle.ManagedDataAccess .
In some cases, I will need to do actions in one transaction, but often not.
I'm not sure the best way to handle DbConnection objects within a single TransactionScope .
I could add DbConnection to the repository, and then even use LifetimePerScope to make sure that they all get the same DbConnection instance. But this is a smart move, is this .Open() connection .Open() .
using (var scope = _lifetimeScope.BeginLifetimeScope()) { var connection = scope.Resolve<IDbConnection>(); var personRepo = scope.Resolve<IPersonRepository>(); var workRepo = scope.Resolve<IWorkRepository>(); connection.Open(); var transaction = connection.BeginTransaction() personRepo.DeleteById(someId); workRepo.DeleteByPersonId(someId); transaction.Commit(); }
This will force me to always use LifetimeScope , even if I donβt use a transaction, and open a connection outside the repository method.
Are TransactionScopes dependent on a single connection, or can I open multiple connections (how does connectionPool handle when a transaction is open?) Within a single transaction?
I am a complete outsider for DbConnections and all this, so I could completely misunderstand the best way to use TransactionScope and DbConnections.
source share