Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Single Database Model - Multiple Connection Strings.

$
0
0

Hello,

Will the following work and be supported in the future ?

1. Reverse engineer the model, use existing database - one of many instances with identical schema .

2. Modify the context like this:

publicpartialclassMyContext:DbContext{
private string connectionString;

public MyContext(string _connectionString) : base ()
{
connectionString = _connectionString;
}

protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.UseSqlServer(connectionString);}

....

3. Create MyContexts locally (without DI) and use different connection strings for databases.

Thanks,

Bartek


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>