I am pulling out my hair, I have no idea why I can’t return the AdPhotos and Location entities. I am using .ToList() shouldn’t it keep the AdPhotos collection intact?
When I place a breakpoint on the return, I can see the data in AdPhotos and Location but after that it disappears.
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;
}
}
Your
Includecall is followed by manual join – that is not supported. Once you use manual join or projection you are changing shape of the query and allIncludecalls are lost.Moreover you don’t need the join because you can write the query like: