-
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
Dynamically Connect to Multiple Databases #6089
Comments
More notes from @GSPP
|
Split out from #4898 |
I tackled this a different way based on my requirements around building modular applications (not specifically multi-tenant). My approach was to define what I call logical groupings, e.g. "Core", "Commerce", "Media", etc. Several modules can belong to the same logical group, i.e. my Security module (Users, Roles, etc.) belongs in Core, as does my Settings module. I defined an attribute which can be used at the context level:
This
This is handled through overriding the
I know this is quite a specialised implementation, but I'd be interested to know what plumbing is changed to support the above request, should it affect my current implementation. |
@rowanmiller my team are hard to look for this feature, yes, we need this feature too.
|
Just like to vote up this feature; we are looking at providing a multi-tenant restful API which switches database context / schema based on URI / JWT user claims; it would be great in to have some way of resolving / dynamically creating a context / connection based on some predicate filter, storing / pooling the resulting instance so it can be reused. |
@rowanmiller Any news on this topic? Edit: I just found this link, and it seems this is the solution for the problem: http://benfoster.io/blog/aspnet-core-multi-tenancy-data-isolation-with-entity-framework |
I also like to vote for this feature (or at least better documentation on the subject). I want to have one database per customer (to make perfectly sure no data can be crossed between customers) I can load a specific connection string based on some information coming from a JWT token (basically what Ben Foster proposed), I'm going to make a POC about it but I'm confident it'll work. I can also use what's explained in #9616. That means having one DbContext that can be different every time. Now with EF Core 2.0, we have DbContext pooling ... which is a very good news for performance and all but I have absolutely no idea of how it'll work when every Context created can be totally different from each other. On the other hand I can create 30~40 different DBContext (DBContextCustomerA, DBContextCustomerB, ...) and having a Factory choosing between everyone of them ...... But it's against every principle I have :( I guess there should be a proper documentation of what is feasible with EF Core and what's the recommanded way of handling many usecase. |
Did the POC for what @seblucas suggested get created? Specifically the "load a specific connection string based on some information coming from a JWT token" part? Would be interested in how to do this. |
What's up with this ? This feature is important to us , we would use this to group some client together instead of using a 1 bucket database.. Our client need to be grouping |
@pilouk This issue is in the Backlog milestone. This means that it is not going to happen for the 3.0 release. We will re-assess the backlog following the 3.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. |
For us a way to specify\construct a different sql connection string would be enough. Preferably WITH db context pooling support of course |
Hi, thanks |
@pilouk My orga has this as a selling point: Database per customer |
I understand, there are many benefits to database per customer. |
In my case its easy because the customers are not connected and every customer has its own instance of the .net app. I don't know about @santosh2812 |
So you don't need to cross query on all context right? |
No we decided against this idea because of the problems named in the issue. But it would be great if we do not have to run the exact same app 80 times. |
@ajcvickers Possible to provide an update or workaround for supporting a query that accesses 2 databases? |
@mrlife I'm not aware of any workarounds that would allow a single EF context to access multiple databases in the same query. |
It's possible to have a single LINQ query that performs a client-side set operation (Concat/Union) or some sort of join over data coming from two different databases (and therefore from two different DbContext instances). Not sure how helpful that is though. |
@ajcvickers Thanks for letting me know. For implementing in EF Core source code, it must be more complicated than adding the name of the database onto beginning of a table reference, e.g. [db-name].[schema].[table-name]? @roji Thanks, that is worth mentioning. The performance would be a consideration, but it could work for some situations. |
From @GSPP' comment in #5626:
The text was updated successfully, but these errors were encountered: