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