如标题描述的一样,在继承 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);
}