I have a UsersContext : DbContext with a DbSet Users { get; set; }
UsersController.cs
public class UsersController : Controller { private UsersContext db = new UsersContext("dbA"); public ViewResult Index() { if (...) db = new UsersContext("dbA"); else db = new UsersContext("dbB"); return View(db.Users.ToList()); } } This returns the good associated list.
If I choose dbB I have the good list but when I go on detail on one of the results in :
public ViewResult Details(int id) { User user = db.Users.Find(id); return View(user); } The db's connectionString is associated to the dbA not the dbB. Why the new db is not well initilized and saved ?