I have an
EntitySet<IEnumerable<T>>
returning from some query and need to cast it to
IEnumerable<T>.
Can I do it?
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.
This looks like a job for SelectMany
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With