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 7 comment(s) |
Filed under:

Comments

Wouter van de Giessen said:

Wooot... I was struggling with this very same issue on and off for the last couple of days. I just could not understand why it did not want to work. So for nested binding with a LinqDataSource you have to have EnableUpdate=true.... Thanks a million for this one Mike.

Cheers

Wouter

# December 11, 2007 6:17 PM

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

Mike Bosch's Blog on .NET said:

I've been really diving head first into the CTP of the ASP.NET MVC Framework as well as getting my hands

# December 26, 2007 10:32 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

Ronan Moynihan said:

Displaying hierarchical data with the LinqDataSource. Don't forget to set EnableUpdate attribute to

# July 2, 2008 8:24 AM

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
Leave a Comment

(required) 

(required) 

(optional)

(required)