EF6 Multi-tenant (multi database) Web App - code first migrations - c#

Surprisingly I can't find anyone with this particular scenario so hear goes. I'm developing a SAAS style MVC/EF web app. I want to offer each customer their own sub-domain name and isolated database, the domain name will determine the name/connection string for the application's single EF context. So when each customer signs up I'll spin up a new database and redirect them to their sub-domain to log in.
However when I switch connection name at runtime, code first migrations do not fire and provision the new database up to the latest version. I'm guessing this is because EF will only fire migrations once per context type for the lifetime of the app. Any suggestions? could I somehow manually fire migrations at application start for all registered sub-domains/databases?

Related

EntityFrameworkCore - It is possible to configure a unique database for each user?

My client asked to build an API in ASP NET Core for a business management application. Nonetheless, he made me an unusual requirement for me: He needs each user to have their own database. All databases have the same structure of tables and relationships and all are MySql.
This means that each user will need their own connection string and some way to store that information.
In addition, other users will be added in the future, each with a bank created just for their use.
Anyway, I don't know if this is possible, but if it is, how would I do it?

Multi Tenancy in ASP.NET

I have the following scenario:
At first I need an application (ASP.NET MVC) with different tenants based on the user login. This step is easy to implement and not need to be answered. Let's say the application is deployed as myapp.com.
On top of the Application a "super-admin" or host should be able to create new tenants for the application.
At runtime the super-admin should be able to set a new application like tenant1.myapp.com. In the backend a new database should be created for the tenant.
My target is to build an application one time and for each new customer just create a new tenant like tenant1.myapp.com with a specific database and let them use it.
How could i implement this? Is it possible to create a new database with Entity Framework and run migrations programmatically?
I hope the question is clear enough.

Versioning issue when updating databases, api and web application

I have thousand of SQL Server databases (one for each client). When we decide to push on production, we have most of the time changes in databases, the web API and the web application.
The problem is the time it takes to deploy everything, especially the databases. We are using Code First migration and MVC .NET and SQL Server, all with the latest version. It is a SaaS. And the code first migration process is able to update the database one-by-one.
The API and the web application are deployed very quickly within a few seconds. However, the databases are all updated within about 30 minutes. During that time some users got errors and cannot use the software because the API tries to target non-updated database. And worse, if during the databases update, something fails and stop, the non-updated users are stuck until we fix the issue and update the rest of the databases.
Any idea how to solve this problem and make clients happy?
PS: The web application doesn't access to the database, but only the API.
This question is somewhat opinion-based. The maintenance window approach is the easiest. If you want to do live-updating, another way would be:
Keep a version number in the database
Allow running multiple versions of the Web API side-by-side
Choose which version of the API to use by looking at the version in the database
Determine if the Web API's public interface is stable. If it is not, also find a way to allow running multiple web sites side-by-side and choose which one based on the version in the database
The most maintainable way to accomplish this would probably be to have at least 3 servers:
One backend server which hosts the old version
One backend server which hosts the new version
The frontend server which routes users to the proper backend server based on the current version.
The routing could take place only at login, or you could do something more fancy such as redirecting the logged-in user when an upgrade is detected. Obviously none of this deals with what happens to one particular client during the actual upgrade of that client's database. You'll still need to address that separately.

Hosting multiple MVC app versions on IIS

I've got a multi tenant asp.net mvc app hosted on iis 8. Each tenant has it's own database, an there is one database with tenants metadata like name, database-name...
As ORM i use Entity Framework with Code-First Migrations.
Now I've got a problem when update the application. because when i start the migration, the App is offline for all tenant because, entity framework can't connect to database with different migration version.
When all Databases are migrated i can start the IIS-Website and all Tenants come online again!
Is there a way to achieve such database migration? OR Am I able to host multiple versions of an MVC App on same Domain (perhaps routing per e.g. http-Header or meta Database)?

Programming c# Entity Framework: Manage User Login

I'm writing a WPF desktop application using Entity Framework to persist user data. I'm using a code first approach and a new database.
In certain scenarios, I would like to restrict access to the database solely from the application, i.e. no user should be able to log into the database outside of the application (e.g. using Management Studio).
I'm struggling to make this work, and initially thought to have the database implement SQL authorization (as opposed to Windows authorization), and have the application generate a unique password on database create. Only the application will therefore know this password, and so only the application will be able to log in and edit the database.
My question is as follows: is this at all possible, i.e. can I generate the login details to the database from my C# application using Entity Framework? Are there any better solutions to this problem?

Categories

Resources