【发布时间】:2014-09-28 18:01:02
【问题描述】:
我正在从事其他人开发的项目。在项目中有
public class HomeController : Controller
{
public HomeController() {
_EntitiesContext = new EntitiesContext();
_UsersContext = new UsersContext();
}
public UsersContext _UsersContext { get; set; }
public EntitiesContext _EntitiesContext { get; set; }
......
然后,每当它需要查询时,它就会使用这些上下文。
通常,我所做的是:我不在 HomeController() 中创建这些上下文,而是在需要时通过 使用 .... 语法创建它们他们。我认为它会打开连接,进行查询,然后关闭连接。否则,连接将始终打开。如果太多人使用它,可能会产生问题。
我说的对吗?我想我以前在网上看过这个,但现在找不到了。
谢谢
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework lifetime