-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-Tenancy with EF 7 #4468
Comments
@unlimitedcoders couple of things to point out, though I'm not sure that they are the root cause of your problems...
This won't work, because DI can't just create instances of your context... it needs to use your
These two are mutually exclusive and should not both be used:
Down to the root cause of your issue... The methods on Here is some code that will create the tables for the current model. There are also methods to check for database existence, etc.
Note that EF Core does not have any mechanism to check if the database contains any tables for the current model... so if you need to check if the tables for the current model already exist then you'll need to do this with ADO.ENT. |
Feel free to reopen if I didn't answer your question |
Thanks @rowanmiller. CreateTables() does the trick. |
I am creating this issue as an extension to the one we have on #4410.
I am trying to create a multi-tenant app with 1 database and different schema for each tenant.
I followed the same approach mentioned in #4410 but it isn't working for me. Here is the code I am running.
I created a separate class called ContextClass to create my DBContext.
From my client (i.e. the controller in my case), I am calling it like-
My CustomerDBContext is like-
On the Startup code-
I want this approach to create the same tables that I have in my CustomerDBContext but in different schemas whenever I called the Create method passing on the schemaname.
Whenever I am calling EnsureCreated or Migrate, it doesn't create any tables. I tried both by creating the migrations and without them.
I also tried another approach where I used the OnModelCreating and passing on the SchemaName like -
Though with this approach, I was able to create tables in my schema the first time using EnsureCreated but it didn't create tables in other schemas when I called Migrate with different schema subsequently.
The text was updated successfully, but these errors were encountered: