I have a bunch of articles and I want to organize them by category. This would be simple with a GroupBy(x => x.Category), except that some articles have multiple categories. How can I group my articles so that if they have two categories, they are put into both category groupings?
example:
Article 1, category:apples, oranges
Article 2, category:apples
Article 3, cateogry:oranges
I would end up with two categories, apples and oranges:
apples: Article 1, Article 2
orange: Article 1, Article 3
Maybe something like this. I have not tried compiling this.
If I've understood your problem correctly, you can do the following:
The relevant
SelectMany
overload is this one.The equivalent query syntax is much nicer:
Thanks to Servy for pointing out the obvious way to translate the fluent version to the query syntax one (I was trying to convert it way too literally).