实体框架 - 上下文处理错误
using(ctx e = new ctx())
{
var pkg = from clPkg in e.PkgCoilPkgs.Include("PkgBand")
.Where(c2 => c2.PkgId == PkgID)
select new PkgCoilcls
{
PkgCoilPkg = clPkg,
};
return pkg.FirstOrDefault();
}
PkgBand
是一个外键表,并且启用延迟加载设置为 true
语句:var pkgBand = PkgCoilPkg.PkgBand.Name;
throws
ObjectContext 实例已 已处置且不能再用于 需要连接的操作” 错误。
即使我使用 Include("PkgBand")
进行加载,为什么我会收到此错误?
using(ctx e = new ctx())
{
var pkg = from clPkg in e.PkgCoilPkgs.Include("PkgBand")
.Where(c2 => c2.PkgId == PkgID)
select new PkgCoilcls
{
PkgCoilPkg = clPkg,
};
return pkg.FirstOrDefault();
}
PkgBand
is a foreign key table and lazy Loading enabled is set to true
statement: var pkgBand = PkgCoilPkg.PkgBand.Name;
throws
The ObjectContext instance has been
disposed and can no longer be used for
operations that require a connection"
error.
Even though I am using Include("PkgBand")
to load, Why I am getting this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢,我使用 Projection 修复了它;选择新的 { PkgCoilPkg, PkgCoilPkg.PkgBand };以下是更多信息:Entity Framework Include() 不起作用
Thanks, I fixed it using Projection ; select new { PkgCoilPkg, PkgCoilPkg.PkgBand }; Here is more info: Entity Framework Include() is not working