tags:

views:

391

answers:

2

I have an

 EntitySet<IEnumerable<T>>

returning from some query and need to cast it to

IEnumerable<T>.

Can I do it?

+1  A: 

This looks like a job for SelectMany

David B
+4  A: 

EntitySet<IEnumerable<T>> implements IEnumerable<IEnumerable<T>>. So you can do this:

IEnumerable<T> flattenedList = entitySet.SelectMany(e => e);

Looks a little strange, but SelectMany takes a function that gets a "child list" from each item on a list and then concatenates all the child lists together into a single list. In this case, each item on the list is a list, so the lambda is nice and short.

Daniel Earwicker