开发者

Entity Framework - context disposed error

开发者 https://www.devze.com 2023-02-08 03:13 出处:网络
using(ctx e = new ctx()) { var pkg = from clPkg in e.PkgCoilPkgs.Include(\"PkgBand\") .Where(c2 => c2.PkgId == PkgID)
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

精彩评论

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