Search code examples
entity-frameworkdbcontextfluent

How to map a table to a context using fluent API?


I present to you my situation: I have 2 tables, for example, orders lists and customers; to each order is associated with a customer, the orders table belongs to "MyDepot" database and the customers table belongs to "Main" database.

I've create 2 different contexts, MyDepotContext and MainContext. How do I map the orders and not customers to the MyDepotContext ? An how do I map customers and not orders to the MainContext ?

Is it possible by using Fluent API ?

Edited : I'm using SQL Server on Azure, so i cannot use the "Linked Servers" functionnality since it's only implemented for Managed Azure SQL Database.


Solution

  • An EF DbContext is bound to a single Database Connection. If you have multiple databases and can't use cross-database queries you'll have to have multiple DbContext types and manage any cross-context operations on the client.