Problem
I have a collection of instances XDocument. Each document has a repeating element that can take on a different meaning. I want to group them by this value, but each element can specify a different value.
<sampledoc>
<value>a</value>
<value>b</value>
<value>c</value>
</sampledoc>
Example
- Document A has the values a, b, c
- Document B has values b, c, d
- Document C has values a, b
I need a group that:
- group a
- group b
- Document A
- Document B
- Document C
- group c
- group d
Question
I am sure I have to do this, but right now I do not see a tree for trees.
docs.GroupBy... ( ), , , , . , LINQ , , .
GroupBy AsLookup LINQ? ?
#, - .
Update
, :
docs.SelectMany(doc => doc.Elements("Value")
.Select(el => el.Value))
.Distinct()
.ToLookup(v => v, v => docs.Where(doc => doc.Elements("Value")
.Any(el=>el.Value == v)));