Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Hierarchical Data
Message
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01324151
Message ID:
01324892
Views:
19
>>I have a table with and ID field and a ParentID field.
>>
>>For a root record, ParentID = ID
>>For a child record ParentID = the ID of the Parent record.
>>
>>All records are in the same table.
>>
>>This is used for holding loose tree structured data. In VFP I would have just walked the tree manually. I just discovered that SQL server will let me show this as a foreign key relationship, which linq may be able to handle... Any idea if this will work?
>
>Interesting. I don't think it actually supports that just yet, but I remember hearing something that it was on their list (some podcast I just listened to, I think).
>
>You could just write a recursive query using CTE to do this instead. Let me know if you need a sample - it's pretty cool.

Hmmm... could swear I responded to this Yesterday.

Had a bit of a problem with the SQL part of this. Kept getting this error which I haven't figured out yet, but which looks like it may be resolvable based on googling a bit.

'cdsContacts' table
- Unable to create relationship 'FK_cdsContacts_cdsContacts'.
The ALTER TABLE statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_cdsContacts_cdsContacts". The conflict occurred in database "cdsData", table "dbo.cdsContacts", column 'ID'.

However... I set up the relationship manually in my Linq DBML and it's sweet. My TreeView now populates itself from the entity data without me having to recurse the tree manually. Each record ends up with both a parent property and a child collection.

I took a look at the CTE stuff and bookmarked it for latter. That is a cool!!! I didn't know about that one and got around it by having a RootID in each record.
Previous
Reply
Map
View

Click here to load this message in the networking platform