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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PrinceT
  • 459
  • 4
  • 19

1 Answers1

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.

John
  • 3,627
  • 1
  • 12
  • 13
  • 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. – PrinceT Dec 20 '14 at 10:34
  • 2
    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. – John Dec 20 '14 at 11:09