efcore 2.2中的多租户配置

时间:2019-04-30 11:56:36

标签: c# sql-server entity-framework

我在一个数据库的多租户应用程序中使用EF Core 2.2。我使用了以下代码:

modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == _tenantId);

OnModelCreating中可以使用,但我想将其应用于我所有具有tenantId的模型中。请告诉我是否有实施此策略的方法。

1 个答案:

答案 0 :(得分:3)

Entity Framework Core 2.0引入了全局查询过滤器,可在创建模型时将其应用于实体。它使构建多租户应用程序和支持实体的软删除变得更加容易。使用此链接:Global query filters in Entity Framework Core 2.0
但您无需在此示例中进行缓存。