We develop a bigger SaaS application based on ASP.NET Core and EFCore. We separate tenants by database, means that we have one database for each tenant.
The database is migrated on any incoming request by a client by a custom middleware. This required, because the application should be immediately available after a tenant signed up on our SSO-Server.
So the pipeline looks like this:
Unfortunately this has some downsides, as I recognized later:
Long introduction, short question: Can anyone judge whether this migration workflow is a good practise? If not: Do you have a better idea how I can achieve multi tenancy?
I read about Global Query Filters in EFCore 2.0, but I'm not sure how safe this approach is regarding data isolation.
Thanks!
I think creating a database per each tenant is not practical. If you have 2000 tenants, then you have to maintain 2000 database instances!
I recommend using 1 database for all the application and tenants. And add a TenantId
to most of tables so you can find out which tenant this specific records belong to.