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

查看:483
本文介绍了为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.

推荐答案

该主题的答案:

数据过滤器可用于选择数据.如果您的实体是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天全站免登陆