简体   繁体   中英

Group by two columns in linq

在此处输入图片说明

Hi
I want to group the above list of stores in this case. The above is a List(of Stores) and I want create a new list of stores where they are all grouped by FromStore and ToStore .

Example:

Dim Test As List(Of Stores) = MyTStores.GroupBy(Function(x) x.ToStore).[Select](Function(grp) grp.First()).ToList()

This example only group by one columns and not two.

.GroupBy(Function(X) New With {X.FromStore, X.ToStore})

或仅此,如果您不关心后续处理中的密钥:

.GroupBy(Function(X) X.FromStore & "-" & X.ToStore)

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