I am implementing a soft delete for our app. To implement soft delete, I am creating ISoftDelete interface and using it to overwrite the default delete behavior of the EF by overwriting SaveChangesAsync for those entities who have implemented the ISoftDelete interface. It works as expected.
Now the problem occurs when I get the data. To ignore soft deleted rows, I need to add where clause to every specification. This is not convenient and prone to error. I want to extend or overwrite specifications to ignore soft-deleted rows from a single point when I get the data for those entities which implement ISoftDelete Interface. Any suggestions?
You can enable this on DbContext level. Here are a few extensions.
Extension for applying soft delete on save:
Then just override the
SavechangesAsync
as followsExtension for applying SoftDelete filter
Then override the OnModelCreating in DbContext and add this call.