Entity Framework 中 使用Include 解决ObjectContext instance has been disposed and can no longer be used for operations that require a connection错误 -原创

ObjectContext instance has been disposed and can no longer be used for operations that require a connection 解决办法:

 

用例介绍:

-----------------------------------------

A和B 1对多关系

A  1->*  B

 

B和C 多对1关系

B  *->1 C

 

现在依赖A查询C

---------------------------------------------

报错的语句

from a in dbContext.A

           select a.B.FirstOrDefault().C;

 

正确的语句

from a in dbContext.A.Include("B.C")

           select a.B.FirstOrDefault().C;

 

 

 

你可能感兴趣的:(Connection)