In MVC we create Dbcontext Models like
public class Model1 : DbContext
{
public Model1()
: base("DefaultConnection")
{}
public DbSet<SomeObj> SomeObjSet { get; set; }
}
//another model
public class Model2 : DbContext
{
public Model2()
: base("DefaultConnection")
{}
public DbSet<SomeObj2> SomeObjSet { get; set; }
}
An then we use controllers like
public class SomeController : Controller
{
private Model1 db1 = new Model1();
private Model2 db2 = new Model2();
public ActionResult Action1()
{
//do sth with Model1 and return
return View(db1.SomeObjSet.ToList());//
}
public ActionResult Action2()
{
//do sth with Model2 and return result
return View(db2.SomeObjSet.ToList());//
}
But my question is that in this way we are creating Multiple DBConnections. Is it better practice to combine the two models into one model and have a dedicated model per controller?