Toggles ABP data filters (ISoftDelete, IMultiTenant) via IDataFilter scopes, checks IsEnabled, performs HardDeleteAsync, and defines custom global query filters for EF Core or MongoDB.
Ships in abp-data-access. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Volo.Abp.Data provides data filters that automatically filter rows when querying the database. Filters are keyed by a marker interface implemented on the entity (ISoftDelete, IMultiTenant, or your own).
ISoftDelete / IMultiTenant in an IDataFilter scope.IsEnabled<TFilter>(), or physically removing a soft-delete row with HardDeleteAsync.AbpDataFilterOptions.ICurrentTenant.Change) — that is the multi-tenancy concern, not a data-filter one.ISoftDeleteMarks an entity as deleted instead of physically removing it. Implement ISoftDelete to add a bool IsDeleted property:
public class Book : AggregateRoot<Guid>, ISoftDelete
{
public string Name { get; set; }
public bool IsDeleted { get; set; } // defined by ISoftDelete
}
When you delete via a repository, ABP sets IsDeleted = true and blocks the real delete, and it automatically excludes soft-deleted rows from queries. The filter is enabled by default — you cannot read deleted rows unless you explicitly disable it. Use HardDeleteAsync on the repository to physically remove a soft-delete entity.
IMultiTenantIsolates data per tenant. Implement IMultiTenant to add a nullable TenantId:
public class Book : AggregateRoot<Guid>, ISoftDelete, IMultiTenant
{
public string Name { get; set; }
public bool IsDeleted { get; set; } // ISoftDelete
public Guid? TenantId { get; set; } // IMultiTenant
}
ABP automatically filters queries to the current tenant based on TenantId. (To switch tenant context you use ICurrentTenant.Change, which is the multi-tenancy concern, not the data-filter one.)
IDataFilterInject IDataFilter and toggle a filter inside a using block. The IDisposable restores the previous state when the block ends:
public class MyBookService : ITransientDependency
{
private readonly IDataFilter _dataFilter;
private readonly IRepository<Book, Guid> _bookRepository;
public MyBookService(IDataFilter dataFilter, IRepository<Book, Guid> bookRepository)
{
_dataFilter = dataFilter;
_bookRepository = bookRepository;
}
public async Task<List<Book>> GetAllIncludingDeletedAsync()
{
using (_dataFilter.Disable<ISoftDelete>())
{
return await _bookRepository.GetListAsync(); // includes soft-deleted rows
}
}
}
IDataFilter members:
IDisposable Disable<TFilter>() — disable a filter for the scope.IDisposable Enable<TFilter>() — enable a filter for the scope.bool IsEnabled<TFilter>() — check current state.Enable and Disable nest, so you can define inner scopes and each restores the outer state on dispose. Always call them inside a using block so the state resets even on exception.
IDataFilter<TFilter>For a single filter you can inject the strongly-typed version and drop the type argument:
private readonly IDataFilter<ISoftDelete> _softDeleteFilter;
// ...
using (_softDeleteFilter.Disable())
{
return await _bookRepository.GetListAsync();
}
It exposes Enable(), Disable(), and IsEnabled — all bound to TFilter.
Use AbpDataFilterOptions to change whether a filter is enabled by default. Example — disable soft delete globally (queries then include deleted rows unless you enable it):
Configure<AbpDataFilterOptions>(options =>
{
options.DefaultStates[typeof(ISoftDelete)] = new DataFilterState(isEnabled: false);
});
Be careful changing defaults for built-in filters, especially when using pre-built modules that assume soft delete is on. Changing defaults for your own filters is safe.
Start with a marker interface and implement it on entities:
public interface IIsActive
{
bool IsActive { get; }
}
public class Book : AggregateRoot<Guid>, IIsActive
{
public string Name { get; set; }
public bool IsActive { get; set; }
}
How the filter is actually applied to queries depends on the database provider — you implement it once per provider you use.
ABP maps filters onto EF Core's global query filters, so they work even when you use DbContext directly. Override ShouldFilterEntity and CreateFilterExpression in your DbContext:
protected bool IsActiveFilterEnabled => DataFilter?.IsEnabled<IIsActive>() ?? false;
protected override bool ShouldFilterEntity<TEntity>(IMutableEntityType entityType)
{
if (typeof(IIsActive).IsAssignableFrom(typeof(TEntity)))
{
return true;
}
return base.ShouldFilterEntity<TEntity>(entityType);
}
protected override Expression<Func<TEntity, bool>>? CreateFilterExpression<TEntity>(
ModelBuilder modelBuilder,
EntityTypeBuilder<TEntity> entityTypeBuilder)
{
var expression = base.CreateFilterExpression<TEntity>(modelBuilder, entityTypeBuilder);
if (typeof(IIsActive).IsAssignableFrom(typeof(TEntity)))
{
Expression<Func<TEntity, bool>> isActiveFilter =
e => !IsActiveFilterEnabled || EF.Property<bool>(e, "IsActive");
expression = expression == null
? isActiveFilter
: QueryFilterExpressionHelper.CombineExpressions(expression, isActiveFilter);
}
return expression;
}
Note the guard !IsActiveFilterEnabled || ... — the filter is applied only while it's enabled, which is what makes Disable<IIsActive>() work. For a single entity you can also chain onto ABP's built-in filters with b.HasAbpQueryFilter(e => e.Name.StartsWith("abp")) inside OnModelCreating.
For MongoDB, filtering goes through IMongoDbRepositoryFilterer and only works when you use the repositories. To add a filter for one entity, derive MongoDbRepositoryFilterer<Book, Guid>, override FilterQueryable, and expose it:
[ExposeServices(typeof(IMongoDbRepositoryFilterer<Book, Guid>))]
public class BookMongoDbRepositoryFilterer
: MongoDbRepositoryFilterer<Book, Guid>, ITransientDependency
{
public BookMongoDbRepositoryFilterer(IDataFilter dataFilter, ICurrentTenant currentTenant)
: base(dataFilter, currentTenant) { }
public override TQueryable FilterQueryable<TQueryable>(TQueryable query)
{
if (DataFilter.IsEnabled<IIsActive>())
{
return (TQueryable)query.Where(x => x.IsActive);
}
return base.FilterQueryable(query);
}
}
The query filter is FilterQueryable — the repository's IQueryable/GetListAsync pipeline runs each registered IMongoDbRepositoryFilterer<TEntity> (and, for keyed repositories, IMongoDbRepositoryFilterer<TEntity, TKey>) through it. So register your subclass for the matching filterer interface; if the entity is used through a keyed repository (IRepository<Book, Guid>), expose IMongoDbRepositoryFilterer<Book, Guid> and derive MongoDbRepositoryFilterer<Book, Guid> (as above) so the keyed pipeline picks it up.
AddGlobalFiltersAsync is a different hook: it builds native MongoDB FilterDefinition<TEntity>s used by the entity/id operations (CreateEntityFilterAsync / CreateEntitiesFilterAsync for get-by-id, delete, concurrency), not the queryable pipeline. Don't override it to add a global query filter — override FilterQueryable for that. The key point is the same as EF Core: honor DataFilter.IsEnabled<...>() so Disable/Enable scopes take effect.
IsDeleted = true) rows and rows outside the current tenant; the same query inside _dataFilter.Disable<ISoftDelete>() returns the deleted rows too.IDataFilter.IsEnabled<TFilter>() reflects the current scope's state and reverts when the using block ends (even on exception).Disable<IIsActive>() returns the otherwise-filtered rows.DataFilter.IsEnabled<...>().using block — the state won't reset on exception (or at all). Always scope Enable/Disable in using.AbpDataFilterOptions defaults for built-in filters — pre-built modules assume soft delete is on; changing that globally can break them. Changing defaults for your own filters is safe.!IsActiveFilterEnabled || ... (EF Core) or the IsEnabled<...>() check (MongoDB) and Disable/Enable scopes silently do nothing.IMultiTenant filters to the current tenant; changing the active tenant is ICurrentTenant.Change, a separate multi-tenancy concern.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
abp-data-filters, soft-delete, multi-tenant, query-filters, ef-core, mongodb
/abp-data-access:apply-data-filtersfrom abp-data-access
npx claudepluginhub abpframework/abp-skills --plugin abp-data-access9 skills in this plugin
/configure-connection-stringsConfigure ABP connection strings for modular and multi-tenant apps — the Default connection, per-module databases, grouping modules into one database, and per-tenant database routing. USE FOR: setting the Default connection, giving a module its own database with a named entry, binding a DbContext via [ConnectionStringName], mapping several modules to one DB with AbpDbConnectionOptions.Databases, routing a tenant to its own database, customizing IConnectionStringResolver. DO NOT USE FOR: EF Core DbContext registration/model config (use ef-core-integration), MongoDB client/database setup (use mongodb-integration), creating tenants or the tenant store (use configure-multi-tenancy), unit-of-work/transaction handling (use manage-units-of-work).
/ef-core-integrationIntegrate Entity Framework Core into an ABP application: AbpDbContext, AddAbpDbContext registration, default/custom repositories, and code-first migrations with DbMigrator. USE FOR: defining an AbpDbContext with ConfigureByConvention, registering it via AddAbpDbContext, wiring AddDefaultRepositories/AddRepository, writing custom EfCoreRepository classes, resolving the active DbContext via IDbContextProvider, adding dotnet ef migrations, running the DbMigrator. DO NOT USE FOR: consuming the standard IRepository method surface — Get/Find/WithDetails/queryable/bulk (use-abp-repositories); MongoDB integration (use mongodb-integration); controlling transaction/UOW boundaries (use manage-units-of-work); soft-delete/multi-tenant/custom query filters (use apply-data-filters); optimistic concurrency stamps (use handle-optimistic-concurrency); Dapper queries (use query-with-dapper); connection-string resolution/config (use configure-connection-strings); seeding data via IDataSeeder (use seed-application-data).
/handle-optimistic-concurrencyEnable and handle ABP optimistic concurrency control so concurrent updates to the same record are detected and rejected. USE FOR: enabling concurrency with IHasConcurrencyStamp/ConcurrencyStamp, deriving from aggregate root base classes to get it for free, flowing the stamp through output and update DTOs, handling AbpDbConcurrencyException when two users update the same record. DO NOT USE FOR: EF-Core-specific mapping/change tracking (use ef-core-integration), MongoDB provider setup (use mongodb-integration), unit-of-work flush/transaction control (use manage-units-of-work), general validation/error surfacing (use handle-validation-and-errors).
/manage-units-of-workControl ABP's Unit of Work — transaction and connection scope, explicit UOW scopes, the [UnitOfWork] attribute, and mid-scope SaveChangesAsync. USE FOR: starting explicit scopes with IUnitOfWorkManager.Begin, applying [UnitOfWork], choosing transactional vs non-transactional boundaries, calling SaveChangesAsync mid-scope, working with nested/RequiresNew/reserved scopes, reading IUnitOfWorkManager.Current, using OnCompleted/CompleteAsync/RollbackAsync. DO NOT USE FOR: defining a DbContext or repositories, or EF Core migrations (use ef-core-integration); MongoDB DbContext/repositories (use mongodb-integration); soft-delete/multi-tenant/custom query filters (use apply-data-filters); optimistic concurrency stamps (use handle-optimistic-concurrency); connection-string resolution (use configure-connection-strings).
/mongodb-integrationIntegrate MongoDB into an ABP application: AbpMongoDbContext, collection mapping, AddMongoDbContext registration, and custom Mongo repositories. USE FOR: defining an AbpMongoDbContext, mapping collections with [MongoCollection]/CreateModel, registering via AddMongoDbContext, wiring AddDefaultRepositories/AddRepository, writing custom MongoDbRepository classes, reaching the DbContext via IMongoDbContextProvider, using GetCollectionAsync/GetAggregateAsync. DO NOT USE FOR: consuming standard IRepository methods (use-abp-repositories); Entity Framework Core integration, DbContext model builder, or code-first migrations (use ef-core-integration); controlling transaction/UOW boundaries (use manage-units-of-work); soft-delete/multi-tenant/custom query filters or MongoDbRepositoryFilterer (use apply-data-filters); optimistic concurrency (use handle-optimistic-concurrency); connection-string configuration (use configure-connection-strings); seeding data via IDataSeeder (use seed-application-data).
/query-with-dapperRun raw SQL via Dapper inside an ABP repository for hot-path read/aggregate queries while sharing ABP's unit of work, connection, and transaction. USE FOR: complex or slow queries where EF Core's generated SQL is too slow, hand-written SQL you want full control over, deriving from a DbContext-based DapperRepository and using GetDbConnectionAsync/GetDbTransactionAsync to stay in the current unit of work. DO NOT USE FOR: standard CRUD/LINQ/change tracking/migrations (use ef-core-integration), MongoDB queries (use mongodb-integration), unit-of-work configuration itself (use manage-units-of-work), connection string routing (use configure-connection-strings).
Other plugins' skills for the same job