Mike Bosch's Blog on .NET

Agile enterprise architecture in .NET, SOA, WCF, WS-*, AJAX, MVC, Sharepoint and more...

Displaying hierarchical data with the LinqDataSource

I ran into some frustration playing with the new LinqDataSource last night.  I was creating a FAQ page for a site and needed to show the Category followed by the list of questions/answers in that category.  This involved having a repeater nested within a parent repeater which was bound to a LinqDataSource.  The child repeater was then bound to the "Faqs" collection of the FaqCategory table.  The Linq to Sql designer is shown below as well as the repeater. 

 

After setting this up, I was not able to get the actual questions to display in the nested repeater.  I thought Linq would delay execution of the query to return the entire object graph.  I finally tried setting EnableUpdate attribute to "true" and was finally able to get the entire object graph. Hopefully this will save others some frustration.

Posted: Dec 02 2007, 11:28 PM by MikeBosch | with 6 comment(s) |
Filed under:

Comments

christian said:

heureka! ive been trying to find a clue about how to actually bind a datasource for the inner repeater. obviously its hard to find because its that simple... thx

# December 22, 2007 6:09 PM

Thany said:

This is not really hierachical data. This is NESTED data. I was actually looking for a way to get a LinqDataSource hooked up to a TreeView...

# December 31, 2007 12:01 PM

Try this said:

You can also put this in the datasource section:

DataSource="<%# container.dataitem.faqs %>"

When doing this I didn't have to enableupdate.

# February 23, 2009 4:23 PM

Peter said:

The problem is that you need to setup the relationship in your dbml. How would you do it without the relationship setup in code?

# April 14, 2010 8:34 PM