question

ErumMirza-7683 avatar image
0 Votes"
ErumMirza-7683 asked DanielZhang-MSFT commented

how to work with different instances of same database with single dbcontext in entity framework core

is there any way to connect with with different instances of same database with single db context in entity framework core/Asp.net core??

Please share sample code and article

dotnet-entity-framework-core
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

any one else can participate

0 Votes 0 ·

Hi @ErumMirza-7683,
May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.
Best Regards,
Daniel Zhang

0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi ErumMirza-7683,
According to my understanding, the context is related to a single database. There is even no easy way to hack it, because the context can still only create queries for a single database, so if you want to access multiple databases, you need to create a context for each database (there is no cross-context query or relationship).
But I also found some methods or suggestions in these threads you can refer to.
EF Core and Multiple Databases
Performing projections on multiple databases with only one dbContext
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.