Solved

recursive query in linq to sql

Posted on 2008-10-10
2
1,199 Views
Last Modified: 2013-11-11
I have a database table that lists product categories and sub categories as follows


Products table.............

                  *producttable*
                   id
                   productname
                   categoryid

then just have a productcategory table like this.....

categoryID     categoryParentID     categoryName
1                              0                              first
2                              0                              second
3                              1                             sub category1 from first
4                              1                             sub category2 from first
5                              2                             sub category from second


I want to query these two tables using linq.  
0
Comment
Question by:mugsey
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 22692610
Hi mugsey;

If you have a Microsoft SQL server or SQL Express you can do the following:
Create a data context class by adding a new Item to the project and the type of the item to create would be a Linq To SQL Classes from the Add New Item dialog box. One you create the data context class drag the two tables on to the design surface and save it. Then you can create the data context class in your code and write the query. If you have a reference constrants in the database this will show up as a line between the two tables in the data context designer. Then you can write your query and access the child table through the parent.

If you do not have a MS SQL database then you will need to create a connection with ADO.Net and load a data set with the tables and query the data table with Linq.

If you would give what the Linq query is to return I will be able to help in constructing the query.

Fernando
0
 

Author Comment

by:mugsey
ID: 22694230
HI Fernando

Thanks for your reply - I will try your suggestion when I get home tonight.  

Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question