Solved

recursive query in linq to sql

Posted on 2008-10-10
2
1,203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…

751 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