Hi all,
I am currently facing a problem related to UnitOfWork. Within the Using block of a UnitOfWork, I would like to perform a save operation for an object which is not part of the UnitOfWork. The save opersion is executed with no result in the database, but also no error or similar. I tried to nest UnitOfWork by creating another UnitOfWork within the first one, but this also did not help. The commit operation of the nested UnitOfWork has no effect.
Background to what I am trying to do: In a custom table, I store some opertaions, which have to be done based on some conditions. These operations can be marked as UnitOfWork. I have the following challenge:
- On the one hand, while performing these operations and putting them in the UnitOfWork I want to report the status of the operation (in progress, waitToCommit, error, etc.) as soon as the operation is done, and can't wait until I perform the commit operation.
- On the hand, the operations stored in the table must be perform as a UnitOfWrok
To do this, I need to perfrom a save operation of the IEntity object, for which I have to report the status. The object is not part of the UnitOfWok and the save operation needs to be done within the Using block, as mentioned above.
It seems that with starting the UnitOfWork a transaction is started and all database operations are executed when the commit operation is executed, even for objects which are not part of the UnitOfWork? Is this correct?
Is there any possibility to interrupt the transaction and to restart it again? Or to start the transaction only for the UnitOfWork, so that other database operations can be done independently?
As a workaround, I created a new collection, in which I collect the operations I want to perform as a UnitOfWork separately, and add them later to a UnitOfWork at once. Doing so I am able to perform db operations. But here I have the disadvantage that errors while committing these operations can't not be catched and handled before. My question here (if the above requirements are not possible): How can I check if the commit operation would result in error or not? How can I make the same check, which is done by IUnitOfWork.Put, without putting the object in the UnitOfWork? Is there any something like TryPut or TryCommit? As far I understood, the IUnitOfWork.Put operation checks if errors would occur.
Thanks a lot for your supprt in advance!