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

Should my DbContext inherit from MultiTenantIdentityDbContext or EFCoreStoreDbContext? #763

Open
MrYossu opened this issue Oct 18, 2023 · 3 comments
Labels

Comments

@MrYossu
Copy link

MrYossu commented Oct 18, 2023

Sorry if this is a dumb question, but I'm very new to Finbuckle, and still trying to get my head around it.

I want to use a single-database approach, and following the Identity sample derived my DbContext from MultiTenantIdentityDbContext (see here for the sample code). To get me going, I hard-coded the tenants in appSettings.json like in that sample, but am now looking at picking them up from the database.

According to the stores doc page, if I want to use the EFCore Store, my DbContext needs to inherit from EFCoreStoreDbContext.

I can't inherit from both, as C# doesn't allow multiple inheritance, so how do I get around this?

Thanks for any help you can give.

@AndrewTriesToCode
Copy link
Sponsor Contributor

Hi, not a dumb question. The "single database approach" term refers to tenant app data not usually the tenant store itself. It is possible to use the same database for the tenant store but under a different db context class.

It can be tricky to user multiple db contexts on the same database but here are some helpful links:
https://stackoverflow.com/questions/11197754/entity-framework-one-database-multiple-dbcontexts-is-this-a-bad-idea
http://msdn.microsoft.com/en-us/magazine/jj883952.aspx

Also, you can use Finbuckle for per-tenant data isolation in a single database without inheriting from MultiTenantIdentityContext but it is a bit tricky. This part of the docs might be helpful:
https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/EFCore#adding-multitenant-functionality-to-an-existing-dbcontext

@AndrewTriesToCode
Copy link
Sponsor Contributor

I'll also add that you can make your own version of the EFCoreStore that doesn't have the requirement that EFCoreStoreDbContext is inherited--it's just an example feel free to customize for your needs.

@MrYossu
Copy link
Author

MrYossu commented Oct 24, 2023

@AndrewTriesToCode Thanks for the comments. Up until I started looking at Finbuckle, I'd never really thought about splitting by dbcontext, I'd always just used one for everything. Still not sure it's such a compelling idea, but I can see where you're coming from.

Thanks again, some bedtime reading there!

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