Support to multiple databases in application
See original GitHub issueHi @hikalkan,
I wanna know how I can use multiple databases in my application. There are any attribute and/or interface to decorate repository to use a specific connectionString/database in repository.
PS: I’m new in ABP, I read the documentation and I don’t found anything to help me.
Could be anything like this:
[UseDatabase("ConnectionStringName")]
public class TaskRepository : SimpleTaskSystemRepositoryBase<Task, long>, ITaskRepository
{
public TaskRepository(IDbContextProvider<SimpleTaskSystemDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
}
Thanks,
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How to Integrate Multiple Databases
Check out our in-depth guide to learn how to integrate multiple databases, for all kinds of app projects.
Read more >Managing Multiple Databases from a Single Application
Querying across Multiple Databases. When it comes to SQL queries, most DBMSes support a standardized set of SQL statements and functions.
Read more >How to create an application supporting multiple databases
I have a situation where I need to create an application which supports multiple databases. Multiple databases means the client can use any ......
Read more >How Do I Provide More than One Database for My ...
A step-by-step guide on how you can provide more than one database for your application on the Cloudways Platform.
Read more >Multiple Databases with Active Record
Multiple Databases with Active Record. This guide covers using multiple databases with your Rails application. After reading this guide you will know:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
It can not be in repository level, but in dbcontext level. Why don’t you create more than one dbcontext? There is an example: https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextDemo
Hi,
Solution 1
The best way, without workaround is to use different classes. For instance, you can derive from Person as a SecondPerson entity and use Person in first dbcontext and use SecondPerson in the second one. In this way, no additional setting is needed, it will just work as expected.
Solution 2
_unitOfWorkManager.Current.SetContextId(firstDbId)
makes your code EF depended. If this is not a problem, theniocManager.IocContainer.ResolveAll<IRepository<Person>>();
(inject IIocManager interface as iocManager)
IRepositoryWithDbContext
and use GetDbContext() method. Then check if the given DbContext is the one you want.You can create a helper method to not repeat yourself every time you need that.