3

I upgraded my abp version from 3.5.0 to 7.0.0.

I set method’s attribute UnitOfWork[IsDisabled = true].

Then I run the code like:

xxRepository.GetAllList()

I get the exception:

Value cannot be null. (Parameter 'unitOfWork').

Why? Why not support getalllist in a disabled unitofwork any more? In this case how can I update 1,000,000 data in a loop?

aaron
  • 39,695
  • 6
  • 46
  • 102
Mark
  • 31
  • 2

2 Answers2

8

ABP v6.4 introduced a breaking change with the removal of conventional interceptors (for IRepository and IApplicationService) in Minimize interception usage #6165 with an option to allow disabling the removal of conventional interceptors.

You should begin a unit of work explicitly:

using (var uow = unitOfWorkManager.Begin())
{
    xxs = xxRepository.GetAllList();
    uow.Complete();
}

You can restore the previous behaviour, though this option may be removed in a later version:

return services.AddAbp<AbpProjectNameWebTestModule>(options =>
{
    options.SetupTest();
// });                                     // Change this
}, removeConventionalInterceptors: false); // to this
aaron
  • 39,695
  • 6
  • 46
  • 102
0
[UnitOfWork(IsDisabled = true)]
public virtual void RemoveFriendship(RemoveFriendshipInput input)
{
    _friendshipRepository.Delete(input.Id);
}

Note that if a unit of work method calls this RemoveFriendship method, disabling this method is ignored, and it will use the same unit of work with the caller method. So, disable carefully! The code above works well since the repository methods are a unit of work by default.

In addition, maybe even disabling the transaction may be sufficient.

References:

berkansasmaz
  • 608
  • 5
  • 16
  • but if i disabled the transaction,you update 1000000 records,you cannot submit all of them in one connection,you have to use CurrentUitOfWork.SaveChanges(), right? It’s far slower and inefficient to update data to database. – Mark Jan 20 '22 at 01:59
  • Yes, that is right. You can create a background job for this and do it there, but regardless of where you are doing it, it makes more sense to use bulk operation and update the data according to batch size as you said. – berkansasmaz Jan 20 '22 at 06:29