A very simple implementation for soft deleting entities in Ef Core library.
Extend your application db context from SoftDeletes.Core.DbContext
.
In entities you want to add soft delete support, implement SoftDeletes.ModelTools.ISoftDelete
interface.
It will a column named DeletedAt
to your entity so you need to add a migration and update the database tables.
Load relations you want to delete in soft deleting the entity in LoadRelationsAsync
and LoadRelations
methods.
Delete relations you want to delete in soft deleting the entity in OnSoftDeleteAsync
and OnSoftDelete
methods.
For soft deleting an entity use Remove
and RemoveAsync
methods. These methods will
soft delete an ISoftDelete
implemented entity and force delete an not implemented entity.
For force deleting any entity use ForceRemove
method.
It doesn't support DbSet
yet, so you have to use SoftDeletes.Core.DbContext
methods for removing
instead of using DbSet
methods.
An interface for saving CreatedAt
and UpdatedAt
date and time of entities.
You can implement it in your entities. That will add to columns named
CreatedAt
and UpdatedAt
to your entities.
An abstract class that implements ITimestamps
and ISoftDelete
interfaces.
You can use it in your entities.
If you like it, you can donate BTC(bitcoin) to this wallet 3MUn52me1PRczXpPQ5PrPZtU8iG1QqeiDY
The proposal for this implementation.