我了解到 IQueryable 或 IEnumerable 数据类型不会首先返回结果,只在需要时才返回结果。但是,当我在 watch inspector 中打开该对象时,我看到所有对象都在那里。
我的代码有什么问题吗?还是因为我在 watch 上调用它才显示出来?
[当我在监视对话框中查看 pendings 对象时,我看到了所有列表项,但它不应该首先加载。我的接近有什么问题还是只是显示因为我在 watch 上打电话。]
public IQueryable<PurchasePendingView> PurchasePendings() {
var pendings = db.PurchasePendingViews
.Where(m => m.AccountStatusID != StructAccountStatus.Succeed); // when I view it in the watch dialougebox I saw all the list items but it shouldn't load at the first place. Is there anything wrong in my approaching or is it just showing because I had call it on the watch.
if (ApplicationEnvironment.DEBUGGING) {
return pendings;
} else if (IsMobileAccount()) {
var showroom = db.ShowRooms.FirstOrDefault(m=> m.MemberID == employee.MemberID);
if (showroom != null) {
return pendings.Where(m => m.ShowRoomID == showroom.ShowRoomID);
} else {
return pendings.Where(m => m.CountryDivisionID == employee.CountryDivisionID);
}
} else {
//normal salary employee can see every detail
return pendings;
}
}
注意:目前我的延迟加载已关闭。
最佳答案
集合会在您第一次遍历结果时进行评估。
由于您在 watch inspector 中迭代结果,因此会对其进行评估。
关于c# - Entity Framework : does IQueryable or IEnumerable get all the results at the first place?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12802226/