开发者

Entity Framework - context disposed error

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?


Thanks, I fixed it using Projection ; select new { PkgCoilPkg, PkgCoilPkg.PkgBand }; Here is more info: Entity Framework Include() is not working

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜