Let say I have a method (example taken from another post):
public IQueryable<CityBlock> GetCityBlocks(){
var results = from o in db.city_blocks
let buildings = GetBuildingsOnBlock(o.block_id) //returns Iqueryable
select new CityBlock {
BuildingsOnBlock = buildings,
BlockOwner = o.block_owner
};
return results;
}
In the calling method I add Skip() and Take() methods plus some filtering and then do a ToList().
The trouble is that I am getting dozens of database calls - one for all the city blocks and then a separate one for each building.
Is there a way that I can refactor this code to just make two calls: one for the city blocks and one for all the buildings
Should add that I have tried eager loading using:
var dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith<city_blocks>(x => x.buildings);
db.LoadOptions = dataLoadOptions;
but does not seem to make a difference.