Navigation of typed dataset in many-to-many relationships

T

Thomas Zaleski

I have 5 tables in my dataset that I have pulled all records for from
the database. The table structure look like this:

Products(productid, productname)
Product2Category(productid, categoryid)
Category(categoryid, categoryname)
Product2Genre(productid, genreid)
Genre(genreid, genre name)

So basically, when someone clicks on a category, i.e. categoryid = 5,
then I would like to pull all associated genres (DISTINCT) for the
products corresponding to category id = 5.

How would I navigate and pull that data.

Please let me know.

Thanks.
 
M

Mikael Gustavsson

Hi Thomas!

If you have created a relation between for instance the Products table and
the Products2Genre tables and that in time to the Genre table then you can
just walk down the hierarchy.

//This will symbolize the fetching of the products
ProductDataSet ds = GetTheProducts();

string categoryName =
ds.Products[x].GetProduct2GenreRows()[y].GetGenreRows()[z].genrename

So in your case you could do it this way

foreach (ProductDataSet.Product2Genre productGen in
ds.Procducts[5].GetProduct2GenreRows())
{
foreach (ProductDataSet.Genre gen in productGen.GetGenreRows())
{
//Do what you want to do with the genre here
}
}

Well, I hope this helps you out a bit in the right direction

//Mikael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top