diff --git a/docs/en/Data-Filtering.md b/docs/en/Data-Filtering.md index 85f094b614..0390c24059 100644 --- a/docs/en/Data-Filtering.md +++ b/docs/en/Data-Filtering.md @@ -151,11 +151,21 @@ public class Book : AggregateRoot, IIsActive ABP uses [EF Core's Global Query Filters](https://docs.microsoft.com/en-us/ef/core/querying/filters) system for the [EF Core Integration](Entity-Framework-Core.md). So, it is well integrated to EF Core and works as expected even if you directly work with `DbContext`. -Best way to implement a custom filter is to override `CreateFilterExpression` method for your `DbContext`. Example: +Best way to implement a custom filter is to override `ShouldFilterEntity` and `CreateFilterExpression` method for your `DbContext`. Example: ````csharp protected bool IsActiveFilterEnabled => DataFilter?.IsEnabled() ?? false; +protected override bool ShouldFilterEntity(IMutableEntityType entityType) where TEntity : class +{ + if (typeof(IIsActive).IsAssignableFrom(typeof(TEntity))) + { + return true; + } + + return base.ShouldFilterEntity(); +} + protected override Expression> CreateFilterExpression() { var expression = base.CreateFilterExpression(); @@ -174,7 +184,7 @@ protected override Expression> CreateFilterExpression, IIsActive ABP使用[EF Core的全局过滤](https://docs.microsoft.com/en-us/ef/core/querying/filters)系统用于[EF Core 集成](Entity-Framework-Core.md). 所以它很好的集成到EF Core中,即使你直接使用 `DbContext` 它也可以正常工作. -实现自定义过滤的最佳方法是为重写你的 `DbContext` 的 `CreateFilterExpression` 方法. 示例: +实现自定义过滤的最佳方法是为重写你的 `DbContext` 的 `ShouldFilterEntity` 和 `CreateFilterExpression` 方法. 示例: ````csharp protected bool IsActiveFilterEnabled => DataFilter?.IsEnabled() ?? false; +protected override bool ShouldFilterEntity(IMutableEntityType entityType) where TEntity : class +{ + if (typeof(IIsActive).IsAssignableFrom(typeof(TEntity))) + { + return true; + } + + return base.ShouldFilterEntity(); +} + protected override Expression> CreateFilterExpression() { var expression = base.CreateFilterExpression(); @@ -174,7 +184,7 @@ protected override Expression> CreateFilterExpression