I currently have made a UnitOfWork implementation which wraps both the database connection and the transaction.
using (var uow = UnitOfWorkFactory.Create())
{
// do db operations here through repositories
uow.SaveChanges();
}
Rollback will be called if SaveChanges haven't been called before the uow gets disposed.
Is it a bad design choice to let the uow handle both the connection and the transaction?
Let's say that I got a ASP.Net MVC website where most of the actions are just fetching information from the database. Are there a performance penalty for creating/committing transactions that aren't actually not doing anything in the database?
If you want to implement UoW then SaveChanges should be the only place where a connection and a transaction will be used. UoW will just collect all commands that must be executed and execute them in a transaction when SaveChanges is invoked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With