为 AbpUserRole 禁用 SoftDelete [英] Disable SoftDelete for AbpUserRole

查看:21
本文介绍了为 AbpUserRole 禁用 SoftDelete的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

By default, the AbpUserRole and AbpRole implement ISoftDelete. Is it possible to disable it?

我尝试这样做:

[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));
    }
}

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

Although the filter is disabled in the current unit of work, it doesn't work. The entity is marked as deleted.

推荐答案

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

数据过滤器用于选择数据.如果您的实体是 SoftDelete,ABP 始终会对其进行软删除并阻止实际删除.

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

您可以覆盖 DbContext 中的 CancelDeletionForSoftDelete 方法并有条件地防止取消.

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

所以,像这样:

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

这篇关于为 AbpUserRole 禁用 SoftDelete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆