Hi folks,
i'm not sure this is the best way to do the following code. I'm not sold on a foreach inside another foreach. Could this be done *better** with Linq?
*I understand that better could be either
a) more performant
b) easier to read / more elegant
c) all of the above
NOTE: .NET 3.5 solutions accepted :) NOTE2: the two IList's were the results of a multi-recordset stored procedure, via Linq2Sql.
here's the make believe code:
// These two lists are the results from a IMultipleResults Linq2Sql stored procedure.
IList<Car> carList = results.GetResult<Car>().ToList();
IList<Person> people = results.GetResult<Person>().ToList();
// Associate which people own which cars.
foreach(var person in people)
{
var cars = (from c in cars
where c.CarId == person.CarId
select c).ToList();
foreach (var car in cars)
{
car.Person = person;
}
}
Cheers :)