zoukankan      html  css  js  c++  java
  • C# Entity Framework The ObjectContext instance has been disposed and can no longer be used for operations that require a connection

    The ObjectContext instance has been disposed and can no longer be used for operations that require a connection

    该对象上下文实例已被释放,不能用于需要连接的操作。

    shared context per request模式,缩短Entity实例的存在时间和降低Entity实例的共享性,并考虑性能,因为Entity需要手动Dispose。

            public override void Dispose()
            {
                string objectContextKey = "MIP_" + HttpContext.Current.GetHashCode().ToString("x"); if (HttpContext.Current.Items.Contains(objectContextKey))
                {
                    SPMIPEntities ctx = HttpContext.Current.Items[objectContextKey] as SPMIPEntities; if (ctx != null)
                    {
                        ctx.Dispose(); HttpContext.Current.Items.Remove(objectContextKey);
                    }
    
                }
                base.Dispose();
            }

    不能使用单例模式,静态方法就可以。

  • 相关阅读:
    php多态简单示例
    php接口
    PHP的两种表单数据提交方式
    PHP操作数据库
    51nod 1575 Gcd and Lcm
    51 nod 1297 管理二叉树
    51 nod 1628 非波那契树
    51 nod 1211 数独 DLX
    51nod:1689 逛街
    51 nod 1203 JZPLCM
  • 原文地址:https://www.cnblogs.com/hofmann/p/11750586.html
Copyright © 2011-2022 走看看