How to implement Soft Delete using Global Query Filters?

Updated Apr 28, 2026

Short answer

Soft Delete marks a record as deleted via a flag instead of physically deleting it. Global Query Filters ensure these records are automatically hidden.

Deep explanation

  1. Add an IsDeleted boolean to your entities. 2. Override SaveChanges to catch EntityState.Deleted, change it to Modified, and set IsDeleted = true. 3. Add HasQueryFilter(e => !e.IsDeleted) in OnModelCreating. All SELECT queries will automatically hide soft-deleted rows.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More Entity Framework interview questions

View all →