Best way of using/querying many databases with the same model with EF Core 2.2

c# entity-framework-core rest sql-server visual-studio

Question

I'm currently working on a project and for some strange reason I have to use 32 different SQL Server databases with the same model. These databases have different information but the same exact design.

For some stupid requirement I can't unify these databases. My problem is that I have to implement some Rest services in C# using EF Core 2.2 that perform queries on these databases.

I suspect that if I create a context for each database, the performance of my services is going to be terrible. I'm right? I wonder if there is an efficient / elegant solution for doing this.

1
0
4/11/2020 5:28:14 AM

Popular Answer

If they all have the same structure (same tables, tables have same properties, etc), then you can have one DbContext but change the connection string on the fly based on which one you are querying. It's easy enough to pass in the connection string to a DbContext, but the exact implementation will depend on what all you're doing.

2
4/11/2020 3:24:57 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow