Skip to content

Delete Operations

Furkan Güngör edited this page Jun 20, 2022 · 3 revisions

Summary

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.

Hard Delete

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);
    }
}

or

public class MyClass
{
    private readonly IRepository repository;
    public MyClass(IRepository repository)
    {
        this.repository = repository;
    }
    public async Task HardDeleteAsync(Guid id)
    {
        var entity = await repository.GetByIdAsync<Car>(asNoTracking: true, id);
        await repository.HardDeleteAsync<Car>(entity);
    }
}

Soft Delete

public class MyClass
{
    private readonly IRepository repository;
    public MyClass(IRepository repository)
    {
        this.repository = repository;
    }
    public async Task SoftDeleteAsync(Guid id)
    {
        var entity = await repository.GetByIdAsync<Author>(true, id);
        await repository.SoftDeleteAsync<Author, Guid>(entity);
    }
}
Clone this wiki locally