标签:
/// <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(); }
标签:
原文地址:http://www.cnblogs.com/Darkon/p/5412133.html