Is UnitOfWork all or nothing - v8.0.1?

Hello Experts,

I have a large number of objects in my UnitOfWork, and it is possible that a few might cause an error when saved. In this scenario, will the uow not save (i.e. commit to database) any object at all, or will it save all objects which didnt generated any errors? I'm looking for enabling the latter behaviour in case it is not the default, any way to do that?

Thanks

Kin

Parents
  • The UnitOfWork is atomic and it will therefore reroll the database transaction used to store the data if an error occurs.

    You can use the <iEntity).Save method, without using the UnitOfWork, if you want to have each save operation as an atomic operation. But this might give you a performance penalty, as bulk processing is not available then.

  • Thanks Markus, I found this:

    uow.ContinueOnError = True

    Would this still save all objects which it can? I would test it myself but unfortunately won't get a chance until early next week so I'm being a bit cheeky and asking here

  • No, it will not. If you choose to set ContinueOnError = True, the UnitOfWork is not throwing an exception when an error occurs. Instead, you need to check the Invalid property. If the property is true, then an error had occurred and the UoW had already written out some DML (Data Manipulation Language) aka SQL code. You would need to throw an exception in that case to initiate the rollback of the underlying transaction of the UoW.

Reply
  • No, it will not. If you choose to set ContinueOnError = True, the UnitOfWork is not throwing an exception when an error occurs. Instead, you need to check the Invalid property. If the property is true, then an error had occurred and the UoW had already written out some DML (Data Manipulation Language) aka SQL code. You would need to throw an exception in that case to initiate the rollback of the underlying transaction of the UoW.

Children
No Data