Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

recursive query in linq to sql

Posted on 2008-10-10
2
Medium Priority
?
1,213 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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