我使用using
块从实体框架中选择数据集:
protected StagingProcessingEngineStatus GetProcessingStatusEntryById (Guid processingId) {
using (var context = new ProcessingEntities()) {
var matchedPlan = context.StagingProcessingEngineStatus.FirstOrDefault(plan => plan.ProcessingId == processingId && plan.Owner == this.UserCredentials.UserId.ToString());
return matchedPlan;
}
}
StagingProcessingEngineStatus
实体包含一个名为StagingRefProcessingEngineLibrary
的另一个实体的导航属性:
public partial class ProcessingEntities : DbContext {
public virtual DbSet<StagingProcessingEngineStatus> StagingProcessingEngineStatus { get; set; }
}
public partial class StagingProcessingEngineStatus {
public virtual StagingRefProcessingEngineLibrary StagingRefProcessingEngineLibrary { get; set; }
}
现在,我尝试使用GetProcessingStatusEntryById
方法的返回值来访问StagingRefProcessingEngineLibrary
的{{1}}属性的内容。
但是给了我以下例外:
ObjectContext实例已被释放且无法使用 操作不再需要连接。
是否有可能在StagingProcessingEngineStatus
块之外访问导航属性的值,如下所示?
using
答案 0 :(得分:0)
要么不处理上下文(删除using
)以保持延迟加载功能,要么不使用紧急加载(.Include(e => e.StagingRefProcessingEngineLibrary
)