• EF创建上下文对象HttpContext和CallContext


      public class BaseController : Controller
        {
            /// <summary>
            /// 方法1
            /// </summary>
            public TestModelContext db
            {
                get {
                    TestModelContext db = CallContext.GetData("DB") as TestModelContext;
                    if (db == null)
                    {
                        db = new TestModelContext();
                        CallContext.SetData("DB", db);

                    }
                    return db;

                }
            }
            /// <summary>
            /// 方法2
            /// </summary>
            public TestModelContext DB2
            {
                get {
                    TestModelContext db = null;
                    if (HttpContext.Items["db1"] == null)
                    {
                        db = new TestModelContext();
                        HttpContext.Items["db1"] = db;
                    }
                    else {
                        db = HttpContext.Items["db1"] as TestModelContext;
                    }
                    return db;
                }
            }
        }

  • 相关阅读:
    jquery 获取当前元素的索引值
    JQuery中根据属性或属性值获得元素(6种情况获取方法)
    jquery如何获取某一个兄弟节点
    JAVA学习<六>
    JAVA学习<四>
    JAVA学习<三>
    iOS定位到崩溃代码行数
    Swift3.0基础语法学习<五>
    Swift3.0基础语法学习<四>
    Swift3.0基础语法学习<三>
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10581267.html
Copyright © 2020-2023  润新知