MVC では、次のような Dbcontext モデルを作成します
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; }
}
次に、次のようなコントローラーを使用します
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());//
}
しかし、私の質問は、このようにして Multiple を作成していることDBConnections
です。2 つのモデルを 1 つのモデルに結合し、コントローラーごとに専用のモデルを用意する方が適切ですか?