本文介绍了为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

您可以在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 10:16