Enity framework not loading relationship even when using include

Posted by dilbert789 on Stack Overflow See other posts from Stack Overflow or by dilbert789
Published on 2010-04-01T16:41:37Z Indexed on 2010/04/01 16:43 UTC
Read the original article Hit count: 223

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?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about lazy-loading