0

So the problem is: I am working with a legacy project. Creating a web interface to databases. ASP.NET Core, CRUD, that usual stuff. BUT! There are 3(three) databases. Let's say there are Companies and Employees tables in each one of them. And there are Companies in the first database which employees may be found in first, second and third databases.

Currently, I am writing custom queries to target multiple databases. Working directly with MySqlConnection classes and MySqlDataReader. It gets the job done, but I am really missing Entity Framework's lazy loading

I know I can create multiple EF contexts, one for each database, but it's not gonna work because as I said - data may be spread out through all 3 DB.

Is there any better way to communicate with multiple databases?

SAVe
  • 814
  • 6
  • 22
  • What won't work with three DataContexts? – schlonzo Jul 24 '19 at 08:45
  • As far as I know. DataContext can only work with one DB. There are Companies in the first database which employees may be found in first, second and third databases. So if i use one DataContext for the first DB. I can't get all employees for a Company without merging results with others. I see no benefit in this. – Alexandr Denschikov Jul 24 '19 at 09:42
  • How is the "merging" workflow right now? I see no problem in using three datacontexts to get three sets of employees and merge the result using _LINQ to Entities_. – schlonzo Jul 24 '19 at 10:54

1 Answers1

0

You can create synonyms in one database for tables located in another database and try to use it in EF.

mtkachenko
  • 5,389
  • 9
  • 38
  • 68
  • Looks like I cant create synonyms in mysql https://stackoverflow.com/questions/15777420/how-to-create-a-synonym-in-mysql But you gave me an idea, maybe views will do the work. In this case performance is the question – Alexandr Denschikov Jul 24 '19 at 09:46