views:

50

answers:

1

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?

EDIT: Using .net 3.5 VS2008

A: 

The include is being dropped because it is associated with the first ObjectQuery and not the result set that is coming back.

I think you just need to rework your query? Unless I am missing something you really want the below, i didn't see anywhere you use the accessory join.

        Category selectedCategory = (
             from c in DB.Category.Include("SubCategory")
                where c.AccCatUID == currentAccessory.AccUID
             select c
         ).FirstOrDefault();

or from the otherside

          var fromAccessoryCategory  = 
          (from a in DB.Accessory.Include("Category.SubCategory") 
             where a.AccUID == currentAccessory.AccUID
           select a.Category).FirstOrDefault();
Nix
This is exactly what I wanted to do originally, but I don't have a AccCatUID property directly accessible on 'c'. I receive this: 'DataLayer.Accessory' does not contain a definition for 'AccCatUID' and no extension method 'AccCatUID' accepting a first argument of type 'DataLayer.Accessory' could be found (are you missing a using directive or an assembly reference?)
dilbert789
you try getting after it using accessory? I just updated the post above? I hope the cardinality is 1 to 1.
Nix
And i dont get your error? when you do the c.AccCatUID its a category not an accessory?
Nix
its a 1:N one accessory only has one category, but a category could have multiple accessories. Then one category could have multiple subcategories under that. think of it like:Category -> wheels /subcategory -> black 20" /Accessory -> black 20" rim part number 12345.
dilbert789