If you want to retrieve only some of the columns then use the following overload:
var result = data.GroupBy(key => key.Role, element => element.DocumentType);
Otherwise you can also use this projection:
var result = data.GroupBy(key => key.Role)
.Select(g => new {
Role = g.Key,
Documents = g.Select(i => i.DocumentType)
});
3
solved How do I group the data received from SQL server