views:

30

answers:

1

Right now I can do this with Linq to SQL

response.write(car.models(0).makes(2).model.car.ID)

of course you wouldn't actually do exactly this but I'm showing how I can go up and down the chain of relationships

Now I want to do the same with simple Class Objects that aren't populated by data from some other source but I can't go "backwards"...

response.write (car.models(0).makes(2)... I can't go back down the relationship here back to car so my question is how can I make it do this? Do I need to populate into a dataset first or something?

A: 

For this kind of operation, you generally are going to have to flatten out the data structure, since you have one-to-many relationship. In LINQ, this is generally accomplished with the SelectMany extension method, or, if you prefer query syntax, like this:

var query = 
    from car in cars
    from model in c.models
    from make in model.makes
    select new { Car = car, Model = model, Make = make };

This will end up traversing the "tree" for you allowing you to process the items one at a time for each path down your object hierarchy tree.

casperOne
sweet - I'll try this out!
EdenMachine