时间:2021-07-01 10:21:17 帮助过:2人阅读
/// <summary> /// 为当前用户创建一个DB对象 /// </summary> public static void CreateCurrentEF() { MyTalkDBEntities mytalkdb = new MyTalkDBEntities(); HttpContext.Current.Items[_MyDB] = mytalkdb; } /// <summary> /// 获取当前对象的DB,属性 /// </summary> public static MyTalkDBEntities GetMyDB { get { return (MyTalkDBEntities)HttpContext.Current.Items[_MyDB]; } } /// <summary> /// 销毁当前对象的DB /// </summary> public static void KillMyDB() { using (GetMyDB) { } }
//在global中调用 protected void Application_BeginRequest(object sender, EventArgs e) { //创建唯一的DB WebHelper.CreateCurrentEF(); }
每个请求设置唯一EFDB
标签: