Entity Framework 出现 "此 ObjectContext 实例已释放,不可再用于需要连接的操作" 的错误
2015-11-23 16:41
615 查看
原因
Entity的导航属性在View中使用,但是该Entity所在的Context已经在Controller中通过 using 释放掉;但是Entity又具有Deferred Query Evaluation性质,因此,导航属性对象没有被加载,从而出现上述错误。解决方案
认真学习msdn教程解决方法一:How to: Explicitly Load Related Objects
禁用Context的Deferred Query Evaluation,然后在查询结束后手动加载所有需要的导航属性解决方法二:How to: Use Query Paths to Shape Results
在查询中声明包含导航属性解决方法三:变成List<T>
相关文章推荐
- Objective-C分类 (category)和扩展(Extension)
- Objective-C 注释规范心得
- Objective-C Runtime 运行时之三:方法与消息
- 深入理解Objective-C:Category (原文基础上有改动)
- Objective-C Runtime 运行时之二:成员变量与属性
- Objective-C Runtime
- JsonArray跟JsonObject用法
- python3 套接字异常(a byte-like object is required not str)
- Objective-C 编码建议
- 谈Objective-C Block的实现
- Objective-C学习——中文URL编码和解码
- ios 64位下编译webrtc的libvpx库出现错误Bad cputype for object file.Currently only tested for CPU_TYPE_x86_64
- [Protractor] Testing With Protractor Page Objects
- object-c定义属性与成员变量的区别
- g++编写与使用动态链接库so(shared object)(附cmake生成动态库)
- [ES6] Converting an array-like object into an Array with Array.from()
- javaScript与Objective-C交互
- 增强现实(AR)笔记4:ObjectRecognition实操
- Java中的Object类
- Understanding Runtime