小编Pie*_*ard的帖子

如何使用接口应用EF Core全局查询过滤器

为了管理软删除的实体,我想对实现 ISoftDelete 的每个实体应用全局查询过滤器,但此代码不起作用:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<ISoftDelete>().HasQueryFilter(p => !p.IsDeleted);
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

System.ArgumentException: 'The entity type 'Shoppy.Core.Commons.ISoftDelete' provided for the argument 'clrType' must be a reference type.'
Run Code Online (Sandbox Code Playgroud)

是否可以使用接口作为实体类型?我应该循环每个modelBuilder.Model.GetEntityTypes()并手动应用查询(像这样)吗?或者也许另一种方式?

感谢您的帮助 !

c# entity-framework-core

5
推荐指数
0
解决办法
2092
查看次数

标签 统计

c# ×1

entity-framework-core ×1