更新时间:2023-02-04 10:14:51
我认为您想转为延迟加载.请参阅此问题,或者设置您的ObjectContext:
I think you want to turn of lazy loading. See this question, either set the ContextOptions property of your ObjectContext:
context.ContextOptions.LazyLoadingEnabled = false;
或者,如果您使用的是.edmx模型,请设置LazyLoadingEnabled批注:
Or, if you're using an .edmx model, set the LazyLoadingEnabled annotation:
<EntityContainer Name="MyEntitiesContext" annotation:LazyLoadingEnabled="false">
当然,您必须确保显式加载所需的数据,然后(使用 ObjectQuery 中的
Include()
方法)代码>.
Of course, you will have to make sure that the data you do need is explicitly loaded then (using the Include()
method on ObjectQuery
.