-
Notifications
You must be signed in to change notification settings - Fork 14
Delete Operations
Furkan Güngör edited this page Jun 20, 2022
·
3 revisions
EasyRepository
contains two different methods for delete operations.
- Classes that inherit from the
EasyBaseEntity
type - Custom types
DeletionDate
and IsDeleted
fields is automatically set in delete operations in classes derived from EasyBaseEntity
type.
Additionally, the SoftDelete
property is available for classes that inherit from the EasyBaseEntity
class.
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task HardDeleteAsync(Guid id)
{
var entity = await repository.GetByIdAsync<Author>(asNoTracking: true, id);
await repository.HardDeleteAsync<Author, Guid>(entity);
await _unitOfWork.Repository.CompleteAsync();
}
}
or
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task HardDeleteAsync(Guid id)
{
var entity = await repository.GetByIdAsync<Car>(asNoTracking: true, id);
await repository.HardDeleteAsync<Car>(entity);
await _unitOfWork.Repository.CompleteAsync();
}
}
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task SoftDeleteAsync(Guid id)
{
var entity = await repository.GetByIdAsync<Author>(true, id);
await repository.SoftDeleteAsync<Author, Guid>(entity);
await _unitOfWork.Repository.CompleteAsync();
}
}
Welcome to the EasyRepository.EFCore
wiki!
Topics:
-
Getting Started
-
Implementations
-
Specification
-
Ardalis.Specification & EasyRepository.EFCore