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.UnProxyrepository) as IRepository<TEntity, TPrimaryKey>;
    if repo == null)
    {
        throw new ArgumentException$"Given {nameofrepository)} is not inherited from {typeofIRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName}");
    }

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

    var tenantId = GetCurrentTenantIdOrNullrepo.GetIocResolver));
    var hardDeleteKey = EntityHelper.GetHardDeleteKeyentity, tenantId);

    hardDeleteEntities.AddhardDeleteKey);

    await repo.DeleteAsyncentity);
}

Published by

风君子

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

发表回复

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