ABP 继承 ISoftDelete 后调用 HardDeleteAsync 实现物理删除

如标题描述的一样,在继承 ISoftDelete 后希望进行物理删除操作时,调用 HardDeleteAsync 方法即可。下面是该方法的内部实现:

public static async Task HardDeleteAsync<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository, TEntity entity)
    where TEntity : class, IEntity<TPrimaryKey>, ISoftDelete
{
    var repo = ProxyHelper.UnProxy(repository) as IRepository<TEntity, TPrimaryKey>;
    if (repo == null)
    {
        throw new ArgumentException($"Given {nameof(repository)} is not inherited from {typeof(IRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName}");
    }

    var items = ((IUnitOfWorkManagerAccessor)repo).UnitOfWorkManager.Current.Items;
    var hardDeleteEntities = items.GetOrAdd(UnitOfWorkExtensionDataTypes.HardDelete, () => new HashSet<string>()) as HashSet<string>;

    var tenantId = GetCurrentTenantIdOrNull(repo.GetIocResolver());
    var hardDeleteKey = EntityHelper.GetHardDeleteKey(entity, tenantId);

    hardDeleteEntities.Add(hardDeleteKey);

    await repo.DeleteAsync(entity);
}

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注