0
我拉出我的頭髮,我不知道爲什麼我不能返回AdPhotos和位置實體。我使用.ToList()不應該保持AdPhotos集合完好?Eager loading在EF無法正常工作
當我把一個斷點上的回報,我可以看到AdPhotos和位置數據,但之後消失。
public List<AdListing> LatestAdListings()
{
using (var db = new AdultdirectoryEntities())
{
var results = (from a in db.AdListings.Include("AdPhotos").Include("Location")
join l in db.Locations on a.LocationID equals l.LocationID
where a.Approved && l.CountryID == Constants.ItemKeys.UsCountryId && a.AdPhotos.Count > 0
orderby a.CreateDateTime descending
select a).Take(5).ToList();
return results;
}
}
在此頁面(http://msdn.microsoft.com/en-us/library/bb896272.aspx)我讀過「當您調用Include時,查詢路徑只對返回的ObjectQuery實例有效,其他ObjectQuery實例和對象上下文本身不受影響。」 我認爲這是我的問題,有沒有人有更好的解決方案來返回完整的關係? – TheWebGuy 2012-02-17 23:17:11