Solved

recursive query in linq to sql

Posted on 2008-10-10
2
1,189 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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
Comment Utility
HI Fernando

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

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now