在VB.NET中用Linq展平分层数据

在VB.NET中用Linq展平分层数据,linq,Linq,鉴于以下结构: Public Class Vendor Public Property Accounts As Account() End Class Public Class Account Public Property Services As Service() End Class Public Class Service Public Property Name As String End Class 如何在给定一个供应商的情况下获得所有帐户中包含的所有服务

鉴于以下结构:

Public Class Vendor
    Public Property Accounts As Account()
End Class

Public Class Account
    Public Property Services As Service()
End Class

Public Class Service
    Public Property Name As String
End Class
如何在给定一个供应商的情况下获得所有帐户中包含的所有服务的平面列表?这就是我迄今为止所尝试的:

vendor.Accounts.Select(Function(acct) acct.Services) 'Returns a collection of services collections

我知道我只是缺少了一个明显的操作员。

您正在寻找SelectMany

vendor.Accounts.SelectMany(Function(acct) acct.Services)
如果您只想要唯一的,请在末尾打一个.Distinct()