ドキュメントには、複数のプロパティのグループ化に関する例があります。
Dim custRegionQuery = From cust In db.Customers _
Group cust.ContactName By Key = New With _
{cust.City, cust.Region} Into grouping = Group
For Each grp In custRegionQuery
Console.WriteLine(vbNewLine & "Location Key: {0}", grp.Key)
For Each listing In grp.grouping
Console.WriteLine(vbTab & "{0}", listing)
Next
Next
キーの各要素のプロパティとグループのプロパティを持つ実際のタイプ(つまり匿名ではない)があるとすると、次のようになります。
Public Class CustomerRegionGroup
Public Sub New(city As String, region as String, customers As IEnumerable(Of Customer))
Me.City = city
Me.Region = region
Me.Customers = customers
End Sub
Public Property City As String
Public Property Region As String
Public Property Customers As IEnumerable(Of Customer)
End Class
元のクエリを書き直して単に返すことは可能ですIEnumerable(Of CustomerRegionGroup)
か、それとも匿名タイプを使用して、最初のクエリの結果に対して2番目のクエリを実行する必要がありますか?