seniorEntity Framework
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
- Add an
IsDeletedboolean to your entities. 2. OverrideSaveChangesto catchEntityState.Deleted, change it toModified, and setIsDeleted = true. 3. AddHasQueryFilter(e => !e.IsDeleted)inOnModelCreating. All SELECT queries will automatically hide soft-deleted rows.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro