A way to do this is
from d in documents
group d by string.Join("", d.Metadata
.Where(m => groupableProperties.Contains(m.Name))
.OrderBy (x => x.Name)
.Select(x => x.Value)
) into g
select g;
This creates two groups, having keys RedCircle
(sample.txt, sample2.txt) and Red
(sample3.txt).
The ordering by name ensures that the key strings will always be the same when the names in groupableProperties
are found.