为 AbpUserRole 禁用 SoftDelete

Disable SoftDelete for AbpUserRole

默认情况下,AbpUserRoleAbpRole 实现 ISoftDelete。是否可以禁用它?

我试过这样做:

[AbpAuthorize(AppPermissions.Pages_Administration_Roles_Delete)]
public async Task DeleteRole(EntityDto input)
{
    using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete))
    {
        var role = await _roleManager.GetRoleByIdAsync(input.Id);
        var users = await UserManager.GetUsersInRoleAsync(role.Name);

        foreach (var user in users)
        {
            CheckErrors(await UserManager.RemoveFromRoleAsync(user, role.Name));
        }

        CheckErrors(await _roleManager.DeleteAsync(role));
    }
}

虽然过滤器在当前工作单元中被禁用,但它不起作用。该实体被标记为已删除。

本主题的回答:https://forum.aspnetboilerplate.com/viewtopic.php?p=6180#p6193

Data filters work on selecting data. If your entity is SoftDelete, ABP always soft-deletes it and prevents actually deleting.

You can override CancelDeletionForSoftDelete method in your DbContext and prevent cancellation conditionally.

所以,像这样:

protected override void CancelDeletionForSoftDelete(EntityEntry entry)
{
    if (IsSoftDeleteFilterEnabled)
    {
        base.CancelDeletionForSoftDelete(entry);
    }
}