473,800 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LINQ. Is this select possible?

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?

Thanks,
Miguel
Jun 27 '08 #1
3 1745
Well, I'm not sure that LINQ will make it any easier, as it will
probably want to walk the children in additional queries.

Actually, I'm not sure this is the way I'd store the data... firstly,
how about an xml column? great for hierarchical data. Alternatively,
perhaps change to a spanning-tree - i.e.

ParentNode Span
Jun 27 '08 #2
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#)
------------------------------------------------------------------------
Jun 27 '08 #3
The links that Frans cites are a similar approach to the "Span" stuff I
mentioned, but they look cheaper to maintain - especially the sub-link
with the Lineage example... I'd go for that ;-p

Of course, as always you need to balance edit performance vs read
performance...

But either way, self-referential data isn't going to play friendly with
LINQ in a "get the entire subtree in one hit" kind of way... this is one
of those occasions where you need to just do it another way.

Marc
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3617
by: php newbie | last post by:
I am getting error messages when I try to delete from a table using the values in the table itself. The intent is to delete all rows from TableA where col_2 matches any of the col_1 values. DELETE FROM TableA FROM TableA x INNER JOIN TableA y ON (x.col_1 = y.col_2) Error msg: The table 'TableA' is ambiguous. Can this be done with SQL or should I use T-SQL with cursors here?
8
3775
by: Penny | last post by:
Hi all, My browser throws this Select Case block back at me pointing out a syntax error on the line: 'Case < 251', between the word 'Case' and the '<' symbol. *************************** intWeightTotal = 550 Select Case intWeightTotal
2
885
by: Nocturnal | last post by:
Would something like this be possible by writing it within VB.net? I would like for a program to open up Lavasoft's Ad-Aware, check for any updates available on the web by clicking on their update button, then if there is an update, download and install it, if there isn't, go ahead and do the next thing such as do a full scan of the hard drive and check for spyware. - Basically what I'm trying to get at is doing everything on...
1
2767
by: panchaga | last post by:
Hi, could any one help me with this select statement. i am using as part of JSP page. i want to use wild cards as part of this select. i am getting error when i use % along with the name. rs = statement.executeQuery("SELECT * FROM lessons WHERE fname='"+ name+ "'"); Thanks
0
1879
by: crljenica | last post by:
I need to turn this select statement into a delete statemen. In other words, I want the results of the select statement deleted from the tables. I have never used a delete statement with a minus command. Can anyone help. SELECT item, ispecyr from itemlist where ispecyr = 79 minus select b.piitem, a.cpspecyr from contproj a, projitem b where a.pcn = b.pcn and cpspecyr = 79
4
1633
by: jmDesktop | last post by:
Hi, I am trying to reference this select: <form id="form3" method="post" action="exceptions.php"> <input type="hidden" name="id" value="<?php p($course->id) ? <input type="hidden" name="grade_itemid" value="<?php p($selectedgrade_item) ?>" /> <input type="hidden" name="sesskey" value="<?php p($USER- <input type="hidden" name="action" value="excepts" /> <select name="members" size="15" multiple="multiple">
1
3481
by: bytesFTW99 | last post by:
I have been struggling with this for some time can anyone help out? just trying to have 3 dropdown boxes that fill depending on what is selected, then in some cases click a button and have the second set of 3 dropdown boxes be filled with the same values. thank you <head> <SCRIPT LANGUAGE="JavaScript" type="text/javascript"> var firstChoice2 = 0; var secondChoice2 = 0;
1
2132
by: moose hoss | last post by:
How would I validate this select box using JavaScript? <form action="pizza/data.php" method="post" name="form" onsubmit="javascript:return form_validation();"/> <select name="team" id="s" multiple="multiple"> <option value="sox" name="one">sox</option> <option value="celtics" name="two">celtics</option> <option value="patriots" name="three">patriots</option> </select>
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.