使用 GetAllInclusion
或 Inclusion
方法时,是否可以自动激活“IsSoftDelete”EF Core 过滤器?
public override Task<PublicationDto> Get(EntityDto<Guid> input)
{
var entity = Repository
.GetAllIncluding(x => x.SocialPosts)
.FirstOrDefault(x => x.Id == input.Id);
return Task.FromResult(entity.MapTo<PublicationDto>());
}
最佳答案
ABP 的 EFCore 版本不会自动过滤除查询的根实体之外的任何内容。如果您查看 AbpRepositoryBase 中的实现,ApplyFilters 只会查看查询所基于的实体,而不是包含的任何内容。
if (typeof(ISoftDelete).GetTypeInfo().IsAssignableFrom(typeof(TEntity)))
{
if (UnitOfWorkManager?.Current == null || UnitOfWorkManager.Current.IsFilterEnabled(AbpDataFilters.SoftDelete))
{
query = query.Where(e => !((ISoftDelete)e).IsDeleted);
}
}
在 EF 的常规实现中(使用 EF v6.x),他们使用 DynamicFilters nuget 包来处理此问题,但 EF Core 不存在该插件。这确实是 EF Core 的限制,比 ABP 的限制更严重。 EF Core 没有可用于修改从 Include 生成的查询的 Hook ,至少我正在阅读的是这样的。
因此,这意味着您需要执行自己的查询来解决此问题。您可以在以下链接中了解如何通过使用投影来过滤包含内容:
关于c# - 包含集合时激活 SoftDelete 数据过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45082759/