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

Erum Mirza 6 Reputation points
2021-07-04T11:51:15.94+00:00

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

Developer technologies .NET Entity Framework Core
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,651 Reputation points
    2021-07-05T05:48:45.7+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.