简体   繁体   English

实体框架核心 - 多租户应用程序

[英]Entity Framework core - multi tenant application

I'm looking to develop a multi-tenant application based on EF core and Azure SQL.我正在寻找基于 EF 核心和 Azure SQL 的多租户应用程序。 I don't want to create separate databases for each tenant.我不想为每个租户创建单独的数据库。 Instead I'd like to provision prefixed tables.相反,我想提供前缀表。 For example:例如:

public class Product : BaseEntity
{
    [DisplayName("Name")]
    [MaxLength(100)]
    [Required]
    public string Description { get; set; }

    [DisplayName("SKU")]
    [MaxLength(30)]
    [Required]
    public string SKU { get; set; }

    [DisplayName("Price")]
    [Column(TypeName = "decimal(18,4)")]
    public decimal Price { get; set; }
}

Resulting in a table per tenant:为每个租户生成一个表:

  • TenantId1_Products TenantId1_Products
  • TenantId2_Products TenantId2_产品
  • TenantId3_Products TenantId3_产品

A new tenant should be able to register itself and EF migrations should trigger their set of tables to be created in the database.新租户应该能够注册自己,并且 EF 迁移应该触发他们在数据库中创建的一组表。

I know it's probably a long-shot, but would this at all be possible with EF core?我知道这可能是一个长镜头,但是 EF 核心是否可以做到这一点? All I can find are examples of dynamic connectionstrings to separate databases.我能找到的只是单独数据库的动态连接字符串的示例。

The way you are doing this will ultimately be the same or higher as a separate database per tenant.您这样做的方式最终将与每个租户的单独数据库相同或更高。 This is usually done via a Customer_ID field to the like which will separate this at a row level (and then be included on every query).这通常通过 Customer_ID 字段来完成,这将在行级别将其分开(然后包含在每个查询中)。

Otherwise you might as well have separate databases so that you get better separation/isolation etc. The extra isolation is particularly nice if you want to scale customers by migrating them to a different/larger environment.否则,您还不如拥有单独的数据库,以便获得更好的分离/隔离等。如果您想通过将客户迁移到不同/更大的环境来扩展客户,那么额外的隔离特别好。

The model you are talking about is actually the worst of both worlds, incurring the costs of separate databases, without the benefits of data-driven multi-tenancy.您所说的 model 实际上是两全其美,产生单独数据库的成本,没有数据驱动的多租户的好处。

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

相关问题 如何在.Net Core中的应用程序class上使用依赖注入来实现实体框架池化上下文以实现多租户? - How to use Dependency Injection on a application class in .Net Core for an Entity Framework Pooled Context to achieve multi-tenant implementation? 实体框架核心多租户:基于另一个列值的自动增量列 - Entity framework core multi tenant : auto increment column based in another column value 如何使用带有MVC4的实体框架在多租户应用程序中过滤DbContext - How to filter DbContext in a multi-tenant application using Entity Framework with MVC4 实体框架6数据库迁移,用于隔离的多租户设置 - Entity Framework 6 database migrations for isolated multi-tenant setup 具有多个数据库和泛型的实体框架多租户架构 - Entity Framework Multi-Tenant Architecture With Multiple Databases & Generics C#.NET实体框架多租户最佳实践 - C# .NET Entity Framework multi-tenant best practice 实体框架6和.Net Core应用程序 - Entity Framework 6 and .Net Core application 实体框架核心的多线程问题 - Multi-threading problems on Entity Framework Core 多租户实体过滤 - Multi-tenant entity filtration 在多租户应用程序中加载特定于租户的变量 - Loading the tenant specific variables in a multi tenant application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM