0

I am using entity framework 6.1 and I have two databases.

  1. CustomerDB
  2. CustomerArchiveDB

Both have a Customer table with columns Name, Address, Year etc.

I want to get all the customers from both databases using Entity Framework.

How do I do this?

1
  • Can't you query the first db then change your connection string then query the second db? Commented Dec 20, 2014 at 13:54

1 Answer 1

1

Create 2 EF models, one for each database. Materialize the objects with ToList or ToArray from each DbContext and then Concat them together in memory.

Sign up to request clarification or add additional context in comments.

2 Comments

both the tables have crores of data, with your approach i have to load all the data in-memory and then perform operation. which would be slow.
The problem is that one EF model can't use 2 connection strings and multiple models can't use joins. Perhaps you can tackle the problem on a lower level in the db itself by creating a view to the archived customers in your active db? Or even a joined view of both the customers tables.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.