[C#] LINQ Group By


In some scenarios, we would like to select each first one row
of the group which we group by personId.

The following code block is a simple example.

var memberList =
    memberSourceData.GroupBy(item => item.personId)
        .Select(chunck => chunck
            .OrderByDescending(c => c.Id)
            .First())
        .ToList();
#C#






你可能感興趣的文章

[ week 6 ] Chrome DevTools 除錯筆記

[ week 6 ] Chrome DevTools 除錯筆記

系列文背景與簡介

系列文背景與簡介

[ week11 ] 實戰練習-部落格(以 PHP 實作前、後端)

[ week11 ] 實戰練習-部落格(以 PHP 實作前、後端)






留言討論