Disable SoftDelete for AbpUserRole

一世执手 提交于 2019-11-27 07:40:11

问题


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

I tried to do this:

[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.


回答1:


Answered in this topic: 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.

So, like this:

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


来源:https://stackoverflow.com/questions/48624498/disable-softdelete-for-abpuserrole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!