Dato il seguente elenco:Linq GroupBy e Aggregate
var data = new[]
{
new {category = "Product", text = "aaaa"},
new {category = "Product", text = "bbbb"},
new {category = "Product", text = "bbbb"},
};
come faccio gruppo che per categoria e restituire un oggetto con la categoria e la descrizione dei diversi testi messi insieme ??
ie. vorrebbe concludere yp con:
{
categroy="Product"
description = "aaaa,bbbb,cccc"
}
provato quanto segue GroupBy e aggregata, ma qualcosa non è giusto
data.GroupBy(x => x.category).Select(g => new
{
category = g.Key,
description = g.Aggregate((s1, s2) => s1 + "," + s2)
});
TIA