Skip to content
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

TenantInfo null in AppDbContext, getting exception - Finbuckle.MultiTenant.MultiTenantException: 'MultiTenant Entity cannot be changed if TenantInfo is null.' #846

Open
PiyushKumar19 opened this issue Jun 25, 2024 · 1 comment
Labels

Comments

@PiyushKumar19
Copy link

I'm trying to implement multi-tenancy by saving and fetching tenants from the database. For that, I created a custom store and registered it in the Program.cs . I've also injected IMultiTenantContextAccessor in AppDbContext.

When I try to make any request for an entity that has IsMultiTenant applied to it, the _multiTenantContextAccessor.MultiTenantContext.TenantInfo gets initialized as null in the AppDbContext constructor, which stays as null until the code execution passes through the Custom store from where it fetches the Tenant from the database (it stays null there also), TenantInfo gets Db fetched tenant data only after executing the Controller constructor.

It does not set the TenantInfo globally with the tenant data fetched from the Db from the custom store.

Here's the repo link - https://github.com/PiyushKumar19/BuckleUp

Please ignore those middlewares and ContextFactory classes, they're not being used anywhere.

@PiyushKumar19 PiyushKumar19 changed the title Finbuckle.MultiTenant.MultiTenantException: 'MultiTenant Entity cannot be changed if TenantInfo is null.' TenantInfo null in AppDbContext, getting exception - Finbuckle.MultiTenant.MultiTenantException: 'MultiTenant Entity cannot be changed if TenantInfo is null.' Jun 25, 2024
@AndrewTriesToCode
Copy link
Contributor

Hi the repo link doesn’t seem to be working.

Can you tell me what your tenant strategy is and also where your dbcontext is used? For example, is it in a controller or during app startup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants