score:21
Accepted answer
why don't you use string.join(ienumerable)
method?
data.groupby(x => x.category).select(g => new
{
category = g.key,
description = string.join(",", g.select(x => x.text))
});
with aggregate
you should do following:
description = g.aggregate(string.empty, (x, i) => x + "," + i.text)
first parameter sets seed start value to string.empty
. second parameter defines method to concatenate current seed value (string
) with current element (anonymous_type
).
score:6
data.groupby(x => x.category).select(g => new
{
category = g.key,
description = g.select(x => x.text).aggregate((s1, s2) => s1 + "," + s2)
});
Source: stackoverflow.com
Related Query
- Linq GroupBy and Aggregate
- Using LINQ on ObservableCollection with GroupBy and Sum aggregate
- LINQ GroupBy Source = A Destination = B or Source = B and Destination = A
- LINQ RowNumber, Aggregate (Sum) and GroupBy
- LINQ Aggregate and GroupBy determining correct data
- LINQ with groupby and aggregate always shows default value
- LINQ with groupby and count
- LINQ aggregate and group by periods of time
- C# Groupby Linq and foreach
- Translate SQL to lambda LINQ with GroupBy and Average
- LINQ - GroupBy a key and then put each grouped item into separate 'buckets'
- Difference between Sum and Aggregate in LINQ
- Simple sql to Linq query with group by and aggregate functions
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Using Linq to GroupBy and Sum datatable
- LINQ aggregate functions on bytes, shorts, and unsigned values
- Linq Select and Aggregate within a single iteration
- LINQ with subselect and groupby to get only the latest version of each item in a list
- Using GroupBy and Max in LINQ Lambda Expressions
- Groupby multiple date properties by month and year in LINQ
- LINQ Source Code Available
- GroupBy String and Count in LINQ
- LINQ Sum Nested collection with GroupBy and OrderByDescending
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- Linq Lambda GroupBy and OrderBy
- How can I code an outer join using LINQ and EF6?
- LINQ - Aggregate and calculate several parameters
- LINQ Lambda efficiency of code groupby orderby
- LINQ Performance with SelectMany, GroupBy and First
- GroupBy in LINQ and set property
More Query from same tag
- LINQ performance implications
- How to convert tsql to linq with max and group by and return String[]
- Exclude property from WebApi OData (EF) response in c#
- Linq - how to loop a tree data structure to build a tree style object
- vb.net LINQ to Object grouping by create date
- How can i send filter to linq expression?
- C# - Select out the lowest of two values when duplicate key is found
- How to compare only date components from DateTime in EF?
- FilterByItems Method not working correctly
- creating Linq to sqlite dbml from DbLinq source code
- Dynamic LINQ - Unable to convert between GUID and string
- LINQ get list from list by comparing enum
- Using Linq with a DbDataReader
- EntitySet<IEnumerable<T>> to IEnumerable<T>
- LINQ to XML & bind to Gridview
- LINQ Grouping a List of Objects into Anonymous Type
- LINQ GroupBy object or only anonymous types?
- LINQ: Checking if a string (variable) contains any of the list of properties
- Use Linq to get Items in List that do not have a match in another list
- linq where contains ALL items in list
- check for a substring(of a string) in the dictionary and return the key's(substring) value
- Is it possible to serialize a grouped list?
- How can i edit multiple SQL Tables in a View in MVC 4 with using Razor engine?
- Convert Function Based on TSQL with Function Based with Entity Framework
- group by value with 2 different value and show in Razor view
- Find a Class object's Item with Maximum character count in a User Defined List
- List<T> Sort Memory Leak
- find record from referenced tables of primary key column
- subtract columns in a table with LINQ
- Does Select() on a List lose track of the size of the collection?