I used to work with Entity Framework and made use of the Unit of Work pattern to store all changes during a request and commit them in a single transaction. Right now I am writing an Umbraco package which frequently uses the Umbraco code API to store or delete data from the database. For example the RelationService. Umbraco automatically saves changes when I call RelationService.Relate or RelationService.Delete.
I want to temporarily store these queries and execute them all in a single transaction when I want to commit my changes. Is this possible at all?
I see the RelationService internally uses Unit of Work and immediately commits changes. Can I somehow wrap another UoW around it and surpress commits made by the RelationService? How can I access the Unit of Work?
Umbraco RelationService:
using (var uow = UowProvider.GetUnitOfWork())
{
var repository = RepositoryFactory.CreateRelationRepository(uow);
if (uow.Events.DispatchCancelable(SavingRelation, this, new SaveEventArgs<IRelation>(relation)))
{
uow.Commit();
return relation;
}
repository.AddOrUpdate(relation);
uow.Commit();
uow.Events.Dispatch(SavedRelation, this, new SaveEventArgs<IRelation>(relation, false));
return relation;
}
Unfortunately still didn't find a solution. It seems like the only way to solve this is by bypassing the Umbraco code API and firing custom SQL queries.
Umbraco has lots of events that fire on save, delete, etc. If you're surpressing the actual database saves in your own UoW, those events could be fired before it's actually persisted!
Unit of work
I used to work with Entity Framework and made use of the Unit of Work pattern to store all changes during a request and commit them in a single transaction. Right now I am writing an Umbraco package which frequently uses the Umbraco code API to store or delete data from the database. For example the RelationService. Umbraco automatically saves changes when I call RelationService.Relate or RelationService.Delete.
I want to temporarily store these queries and execute them all in a single transaction when I want to commit my changes. Is this possible at all?
I see the RelationService internally uses Unit of Work and immediately commits changes. Can I somehow wrap another UoW around it and surpress commits made by the RelationService? How can I access the Unit of Work?
Umbraco RelationService:
Unfortunately still didn't find a solution. It seems like the only way to solve this is by bypassing the Umbraco code API and firing custom SQL queries.
Umbraco has lots of events that fire on save, delete, etc. If you're surpressing the actual database saves in your own UoW, those events could be fired before it's actually persisted!
is working on a reply...