使用像这两种方法这样的上下文有什么区别
public class MyController : Controller
{
MyContext db = new MyContext();
public ActionResult Index()
{
return View(db.Users.First(m => m.Id == 1));
}
// ...
}
或者
public class MyController : Controller
{
public ActionResult Index()
{
using (MyContext db = new MyContext())
{
return View(db.Users.First(m => m.Id == 1));
}
}
// ...
}