Entity framework not loading relationship even when using include
- by dilbert789
I have this code:
Category selectedCategory = (from c in DB.Category.Include("SubCategory")
join a in DB.Accessory on c.AccCatUID equals a.Category.AccCatUID
where a.AccUID == currentAccessory.AccUID
select c).FirstOrDefault();
It works fine, selectedCategory gets populated as expected. BUT selectedCategory has a child table 'SubCategory' which does not get loaded even though there is the include there. It is not loaded until I do this:
selectedCategory.SubCategory.Load();
Why do I have to call load explicitly in order to load the child table?