[英]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:为每个租户生成一个表:
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.