【发布时间】:2009-05-07 21:10:46
【问题描述】:
在 ASP.Net MVC 教程中,LINQ to Entities 代码如下所示:
public class MyController : Controller
{
private Models db;
public ActionResult Index()
{
db = new Models();
var foo = (from f in db.foo select f).ToList();
return View(foo);
}
}
我猜这与线程安全/连接池有关,但我只是想知道是否有人知道不这样做的充分理由:
public class MyController : Controller
{
private readonly Models db = new Models();
public ActionResult Index()
{
var foo = (from f in db.foo select f).ToList();
return View(foo);
}
}
【问题讨论】:
标签: c# .net asp.net-mvc linq linq-to-entities