score:5

Accepted answer

You need to use SelectMany to concatenate result sets.

var items = employees.SelectMany(e => e.Orders.Select(o => new Item(e.ID, o.ID)));

score:3

The extension method you're looking for is called "SelectMany": http://msdn.microsoft.com/en-en/library/system.linq.enumerable.selectmany.aspx

score:3

Have a look at Enumerables.SelectMany(), see the example in this Stack Overflow question.

score:5

For what it's worth, this can be written somewhat more succinctly and clearly in LINQ syntax:

var s = from e in employees
        from o in e.Orders
        select new Item(e.ID, o.ID);

Related Articles