0
我正在處理一些繼承的代碼,我不使用實體框架工作。我試圖弄清楚爲什麼以前的程序員按照他們所做的方式編碼,有時會混合和匹配查詢數據的不同方式。JQPL createQuery vs實體對象循環
Deal d = _em.find(Deal.class, dealid);
List<DealOptions> dos = d.getDealOptions();
for(DealOptions o : dos) {
if(o.price == "100") {
//found the 1 item i wanted
}
}
然後有時候我看到這一點:
Query q = _em.createQuery("select count(o.id) from DealOptions o where o.price = 100 and o.deal.dealid = :dealid");
//set parameters, get results then check result and do whatver
我明白的代碼兩件做的,我明白,既然有一個大的數據集,第二種方式更爲有效。但是,只給出幾條記錄,是否有任何理由不做查詢,而只是讓實體執行連接並循環遍歷記錄集?