Skip to content
Advertisement

Return IEnumerable rather IEnumerable

I need to join two tables and get the data from one of the table using linq.

The join works fine but it returns IEnumerable <$IEnumerable><$Ojbect> and I need IEnumerable<$Object>

Here is the code:

Thanks

Advertisement

Answer

In general, when you want to “flatten” a collection, SelectMany is the construct you’re looking for.

In LINQ Query Syntax, that’s accomplished with multiple from clauses:

Or, more simply:

Looking at your query a little more closely, you could probably just avoid the into clause and rely on the join output to give you what you want, though.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement