简体   繁体   English

efcore 2.2中的多租户配置

[英]Multitenant configuration in efcore 2.2

I use EF Core 2.2 in a multi tenant application with one database. 我在具有一个数据库的多租户应用程序中使用EF Core 2.2 I used the following code: 我使用了以下代码:

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

in OnModelCreating and it works but I would like to apply it to all of my models that have a tenantId . OnModelCreating ,它可以工作,但我想将它应用于我的所有具有tenantId模型。 Please tell me if there is a way to implement this strategy. 请告诉我是否有办法实施此策略。

Entity Framework Core 2.0 introduces global query filters that can be applied to entities when model is created. Entity Framework Core 2.0引入了全局查询过滤器,可在创建模型时应用于实体。 It makes it easier to build multi-tenant applications and support soft deleting of entities. 它使构建多租户应用程序和支持软删除实体变得更加容易。 use this link: Global query filters in Entity Framework Core 2.0 使用此链接: Entity Framework Core 2.0中的全局查询过滤器
but you dont need caching in this sample. 但是你不需要在这个示例中进行缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在多租户温莎城堡配置中迷失 - Lost in multitenant Windsor Castle configuration Azure AD多租户WebApi承载授权配置 - Azure AD Multitenant WebApi Bearer Authorization Configuration 可选外键的错误 EFCore 实体配置 - Wrong EFCore Entity Configuration for optional foreign key EFCore 2.2 无法为 CLR 类型“Expression[]”找到到关系类型的映射 - EFCore 2.2 No mapping to a relational type can be found for the CLR type 'Expression[]' 数据库集<User> .Where() 总是返回 null EFCore2.2 - DbSet<User>.Where() always return null EFCore2.2 奇怪的行为表达<Func>在 EfCore HasQueryFilter 方法 v2.2 中(重构问题) - weird behavior Expression<Func> in EfCore HasQueryFilter method v2.2 (Refactoring problem) 使用LazyLoadedProxies时,efcore 2.2关闭特定查询的代理创建 - efcore 2.2 turn off proxy creation for a specific query when Using LazyLoadedProxies .NET Core 2.2下配置中的AddJsonFile选项的默认设置是什么? - What is the default for AddJsonFile options in configuration under .NET Core 2.2? .Net Core 2.2启动中的Services.Configuration.Replace - Services.Configuration.Replace in .Net Core 2.2 Startup Netcore2.2 应用程序在 Linux 机器上的发布配置中中止 - Netcore2.2 app aborts in release configuration on a Linux machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM