2
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?

leppie
  • 115,091
  • 17
  • 196
  • 297
mxasim
  • 2,153
  • 21
  • 15

1 Answers1

1

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

Community
  • 1
  • 1
mxasim
  • 2,153
  • 21
  • 15