shapper wrote:
Hello,
I created an SQL table using the Adjacency Model described here:
http://www.sqllessons.com/categories.html
By using this model I am able to hold many categories and
subcategories in one table.
I then need to create a Site Map using <uland <liHTML tags.
I am trying to solve 2 problems, using LINQ:
1. Get all child nodes given the ID of a certain Node.
2. Get all categories and subcategories in one query.
Could someone help me doing this with LINQ?
Don't use the adjacency model for storing trees in a table, as it's
hard to query a hierarchy.
You could solve your problem with a second table which actually
precalculates the hierarchy and with every update on yuor main model,
recalculates the hierarchy. Then you can with a single join obtain the
complete tree with predicates.
Another way to store a tree is using the CELKO way (weighted tree
model)
See for a discussion, SQL code on the precalc hierarchy and links to
CELKO's article here:
http://www.llblgen.com/tinyforum/Mes...?ThreadID=3208
after you've solved the hierarchy problem, the query you need is easy
to write.
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------