Reputation: 334
I would like to get collection or list of Item objects, but I get array of arrays now.
Item[][] s = employees.Select(e => e.Orders.Select(o => new Item(e.ID, o.ID)).ToArray()).ToArray();
Can anyone select me solution to do it?
P.S. just LinQ solution :)
Upvotes: 3
Views: 373
Reputation: 33388
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);
Upvotes: 5
Reputation: 38610
Have a look at Enumerables.SelectMany()
, see the example in this Stack Overflow question.
Upvotes: 3
Reputation: 18877
You need to use SelectMany
to concatenate result sets.
var items = employees.SelectMany(e => e.Orders.Select(o => new Item(e.ID, o.ID)));
Upvotes: 5
Reputation: 15867
The extension method you're looking for is called "SelectMany": http://msdn.microsoft.com/en-en/library/system.linq.enumerable.selectmany.aspx
Upvotes: 3