tags:

views:

355

answers:

2

Hi,

I have a self referencing table named categories that has a parentcategoryid column that is nullable.

When I added the table to the entity designer it created two navigation properties for this relationship and I named one ParentCategory (the zero or 1 nav prop) and the other I named SubCategories (the * many nav prop).

Everything works great except when I go more than one level deep it doesn't pick up the deeper levels.

So I get all the Category.SubCategories but I don't get the categories under the subcategories.

Am I missing something? starting to think I should have stuck with NHibernate. Shouldn't the deeper levels get lazy loaded?

    return from c in _entities.ContentCategorySet.Include("SubCategories")       
           where c.ParentCategory == null
           orderby c.Importance, c.Title
           select c;
A: 

That's how I would Imagine the SubCategories property to behave.

Level 1

++ Level 2

++ Level 2

++ ++ Level 3

Where SubCategories property of Level 1 only returns Level 2 items. Then to get to Level 3 you would access the consecutive Level 2 items, in a recursive method.

Colin
I guess you are right, I thought there should be some entity magic there but ya I'll have to build them myself.
MvcCmsJon
I do already have a recursive method though. The problem is that they other categories aren't loaded into the entity. You are saying I need to go query for the deeper nodes to build the entity?Just want to be sure I am understanding. It seems like this should be something that can be lazy loaded.
MvcCmsJon
Here is my linq return from c in _entities.ContentCategorySet.Include("SubCategories") where c.ParentCategory == null orderby c.Importance, c.Title select c;
MvcCmsJon
+1  A: 

OK, At least part of the problem is

where c.ParentCategory == null

When I remove that I get the deeper levels but then have subcategories on the top level. I guess I can just filter them out after the fact.

MvcCmsJon

related questions