Hi,
What do I do if I have one module that needs to access 3 different databases.
Creating additional contexts does not seem to work.
When I run the migrator, it fails with an error: Invalid object name 'AbpUsers'
I have read through:
The closest I came to a possible answer is at https://docs.abp.io/en/abp/master/Connection-Strings#database-migrations-for-the-entity-framework-core, but I do not understand it
Thank-you!
What do I do if I have one module that needs to access 3 different databases.
Can you explain the use case in detail?
Hi @maliming ,
Thanks for responding. Sorry for the late reply. I have now managed to make it work, but would still need guidance if it is good practice
I have a single module which needs to access 3 different databases.
In the _MyCompany.Project._EntityFrameworkCore, I have 3 different DbContexts of type
AbpDbContext<MyDbContext>, IMyDbContext
Each has a relevant [ConnectionStringName()] attribute
The difference between my additinal DbContexts and the one generated by the ABP template is that they just have the constructor
In the _MyCompany.Project._EntityFrameworkCoreModule, I then add the additional contexts in public override void ConfigureServices(ServiceConfigurationContext context) method
It now works.
Question is, is this the recommended practice?
I think that's a good implementation: Create one DbContext for each database you want to connect with different ConnectionStringName attributes. If target databases have necessary tables then it will work as expected.
Thank-you
Very useful... thanks for sharing. I did the same thing.