【发布时间】:2014-01-29 18:35:33
【问题描述】:
我设置了以 after a post here on stackoverflow 为模型的 DbContext,在此处找到。
这是当前设置...
public static class DbContext
{
public static MyDbContext Db
{
get
{
if (!HttpContext.Current.Items.Contains("_db"))
{
HttpContext.Current.Items.Add("_db", new MyDbContext());
}
return HttpContext.Current.Items["_db"] as MyDbContext;
}
}
}
上下文在 end_request 上的 global.asax 中设置,如下所示:
void Application_EndRequest(object sender, EventArgs e)
{
var db = (MyDbContext)HttpContext.Current.Items["_db"];
if (db != null)
db.Dispose();
}
这样,在我的整个系统中,我都可以像DbContext.Db.xxxx一样访问数据库
到目前为止,我在本地运行的一切都很好,但是,我还没有在生产环境中对多个用户进行测试。
我的担忧...
I read this post on stackoverflow 现在让我担心多个用户访问静态上下文可能会出现数据问题。这应该让我担心还是我的设置方式可以?
【问题讨论】:
标签: c# asp.net ef-code-first dbcontext