public connectionNames = new Dictionary<int, string>
{
{1, "DB1"},
{2, "DB2"},
{3, "DB3"},
}
var currentDb = HttpContext.Session["CurrentDb"];
var context = new MyDbContext(connectionNames[currentDb]);
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=127.0.0.1;Initial Catalog=DB1;user id=sa;password=pass;",
"DefaultConnection2": "Data Source=127.0.0.1;Initial Catalog=DB2;user id=sa;password=pass;"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
public void ConfigureServices(IServiceCollection services)
{
string connection = Configuration.GetConnectionString("DefaultConnection");
string connection2 = Configuration.GetConnectionString("DefaultConnection2");
services.AddDbContext<Context>(options =>
options.UseSqlServer(connection, o => o.UseRowNumberForPaging()));
services.AddDbContext<Context>(options =>
options.UseSqlServer(connection2, o => o.UseRowNumberForPaging()));
public class HomeController : Controller
{
const string SessionDB1 = "DB1";
const string SessionDB2 = "DB2";
public IActionResult Index()
{
HttpContext.Session.SetString(SessionDB1, "DB1");
HttpContext.Session.SetString(SessionDB2, "DB2");
return View();
}
public IActionResult About()
{
ViewBag.DB1 = HttpContext.Session.GetString(SessionDB1);
ViewBag.DB2 = HttpContext.Session.GetString(SessionDB2);
return View();
}
}
public Context(DbContextOptions<Context> options)
: base(options)
{
//Database.EnsureCreated();
}
public Context()
{
}
select new SomeType()
может бытьselect new ItemViewModel()
? Что- то не пойму откуда SomeType тут. Если да, то к сожалению получаю 2 ошибки.