https://github.com/brianlparker/multitenantdbcontext
https://github.com/brianlparker/multitenantdbcontext
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/brianlparker/multitenantdbcontext
- Owner: BrianLParker
- License: mit
- Created: 2023-12-02T01:03:06.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-02T13:12:49.000Z (over 2 years ago)
- Last Synced: 2025-03-13T16:22:47.565Z (over 1 year ago)
- Language: C#
- Size: 193 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# MultiTenantDbContext
How I generated the Migrations and Optimizations
`ApplicationDbContext`
```
Add-Migration -Context ApplicationDbContext CreateInitialIdentitySchema -OutputDir Data/Migrations/IdentityContext
Optimize-DbContext -Context ApplicationDbContext -OutputDir Data/Optimizations/IdentityContext
```
`TenantDbContext`
```
Add-Migration -Context TenantDbContext CreateInitialTenantSchema -OutputDir Data/Migrations/TenantContext
Optimize-DbContext -Context TenantDbContext -OutputDir Data/Optimizations/TenantContext
```
This will create ApplicationDbContext for all users.
```
Update-Database -Context ApplicationDbContext
```
There is no point doing this for tenant database as it has a dynamic connection string.
When the user navigates to the Tenant Data the service will create the Tenant Database if not initialized.
`appsettings.json`
```js
"Tenants": [
"TenantA",
"TenantB",
"TenantC"
],
```
These strings appear on Register screen and become a claim for the user.
The selected string will also become part of the connection string for the database.
Adding more strings here will add more tenants.