我瞭解到IQueryable或IEnumerable數據類型不會在第一時間返回結果,只會在需要時返回結果。但是,當我在手錶檢查員中打開該對象時,我看到所有對象都在那裏。EntityFramework:IQueryable或IEnumerable在第一個地方獲得所有結果嗎?
我的代碼有什麼問題,或者只是因爲我把它叫做手錶而顯示?
[當我在手錶對話框中查看掛件對象時,我看到了所有列表項,但它不應該加載到第一個位置。這有什麼錯在我接近,或者它只是顯示,因爲我已經把它的手錶]
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;
}
}
注:目前我的延遲加載是關閉的。
這樣做是否意味着我的查詢實際上沒有在第一個地方加載任何東西,並在結束時將它們返回到它將加載的東西? – user1542653
@ user1542653 - 不。這意味着您的方法返回IQueryable對象,然後結果將在第一次調用者迭代結果時加載。 –
不,即使你返回它,它也不會加載,直到某些調用代碼迭代返回。 –