Queries accross multiple databases

Required Nuget Package:
Thinktecture.EntityFrameworkCore.SqlServer

Motivation

Enables executing queries across multiple databases.

Activate the feature

Implement the interfaces ITenantDatabaseProviderFactory and ITenantDatabaseProvider which provide the current tenant (a string) and the database names for provided table name and schema.

Please note: the database names must not change for the same tenant! The implementation of the ITenantDatabaseProviderFactory must be designed so it can be registered as a singleton.

var services = new ServiceCollection() 
                       .AddDbContext<DemoDbContext>(builder => builder
                               .UseSqlServer("conn-string", 
                                             options => options.AddTenantDatabaseSupport<DemoTenantDatabaseProviderFactory>());