Multiple contexts with Entity Framework 6, reference entities across dbcontexts

前端 未结 1 446
醉酒成梦
醉酒成梦 2021-01-16 00:24

I am writing two MVC5 (with EF6 and code-first) web apps using generic UnitOfWork that gets the dbContext injected by Unity.

We are required to have two databases (

相关标签:
1条回答
  • 2021-01-16 01:03

    The easiest approach would be to link tables from one database to the other so that this is the database server which handles two physical databases as one virtual database.

    Then, in EF, you have just one context with tables from both databases and querying/joins etc. works correctly.

    http://msdn.microsoft.com/en-us/library/ff772782.aspx

    Otherwise, linking two databases in the application layer with EF and two contexts sounds impossible.

    0 讨论(0)
提交回复
热议问题