locked
Linq to SQL display data from two tables to a single hierarchical unordered list RRS feed

  • Question

  • Hello all I wrote a question in the asp.net mvc forum here and am wondering if anyone with linq to sql experience can help me.

    As said in the subject line,  I have two tables, one with categories and other with items  and want to display them as a  hierarchical unordered list as seen in my post here:

    http://forums.asp.net/t/1489511.aspx

    Currently I'm working in asp.net mvc, which has the code spread in the controller .cs file as well as some of the list code in the view .aspx page. 

    there is a linq to sql in the database model file, and the code on the controller is using DataContext .

    I wouldn't mind getting advice on doing this as simply as possible with a linq to sql query that could give me the desired result, with variable that I could eventually pass the the html page if necessary, but I don't know If I should:

    1. continue pulling trying to code in what I have which has lead me to a dead end with a static variable/parameter
    2. try a nested for loop in a for loop of the query
    3. possibly try a a left join which I believe is a group join in LINQ then rework my Ilst
    4. how to get a dynamic variable of the category code to pas to the query for the item query
    5. other

    Any thoughts or advice  on which direction to take will be much appreciated.
    Friday, November 6, 2009 5:17 PM

Answers

  • My advice is to use Linqpad to get the data massaged into what you are looking for first, then worry about binding the controls. I have an article which is not directly related but shows how to flatten linq table data which could be helpful to you(?) Linq: Flatten Tercerary Table Data Problem . HTH
    William Wegerson (www.OmegaCoder.Com)
    • Marked as answer by Yichun_Feng Thursday, November 12, 2009 9:39 AM
    Friday, November 6, 2009 5:31 PM

All replies

  • My advice is to use Linqpad to get the data massaged into what you are looking for first, then worry about binding the controls. I have an article which is not directly related but shows how to flatten linq table data which could be helpful to you(?) Linq: Flatten Tercerary Table Data Problem . HTH
    William Wegerson (www.OmegaCoder.Com)
    • Marked as answer by Yichun_Feng Thursday, November 12, 2009 9:39 AM
    Friday, November 6, 2009 5:31 PM
  • thanks for the link I will try it out to see if it can work
    Friday, November 6, 2009 10:10 PM