I have a categories table "Category" [ID, Title] and a Parent/Child table "CategoryParent" [ID,CategoryID,ParentCategoryID] where a many-to-many tree is represented by the parent of a category being indicated using the ParentCategoryID field in the join table.
I thought this would be a simple structure to use to retrieve root categories (category entries which have NULL as a ParentCategoryID value in the join table) and child categories (by parent id.)
However, none of my attempts to write a LINQ2SQL statement to get a list of Category objects by their parent ID in the join table have produced anything compilable.
I would post some code, but none of it is either (a)complete or (b)sensible - in any terms at all.
How should one go about this?
My join table looks like this:
CategoryParent
---
ParentCategoryID [int] (PK)
CategoryID [int] FK
CategoryParentID [int] FK
My data (category) table looks like this:
Category
---
CategoryID [int] PK
Title [nvarchar]
There are two relationships:
Category.CategoryID 1->* CategoryParent.CategoryID
Category.CategoryID 1->* CategoryParent.ParentCategoryID
I would like to provide either NULL or a CategoryID and get back all the Category table rows which have it as a parent.