简体   繁体   中英

How to concat string in LinQ group

var list = Table
    .GroupBy(t => t.GroupId, (key, g) => new {key, g})
    .Select(t => new Transaction
    {
        Date = t.g.First().DateCreate,
        Reference = $"{t.g.First().AccounttName} {t.g.Select(z => z.DocumentNo)}",
        TotalAmount = t.g.Sum(x => x.y.Amount.Value),
    })

When grouping with linQ I know how to get a single value with First(), sum with Sum() but what should I do to concact a string value?

In my example how can I merge all my DocumentNo?

使用string.Join

Reference = $"{t.g.First().AccounttName} {string.Join(",",t.g.Select(z => z.DocumentNo))}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM