I'm looking to develop a multi-tenant application based on EF core and 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.
I know it's probably a long-shot, but would this at all be possible with EF core? 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).
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.